@Override public boolean assertMatches(Predicate<LogMessage> predicate) throws Error { boolean matched = matches(predicate); if (!matched) { throw new AssertionError("did not match " + predicate.toString()); } return true; }
@Override public boolean assertMatches(Predicate<LogMessage> predicate) throws Error { boolean matched = matches(predicate); if (!matched) { throw new AssertionError("did not match " + predicate.toString()); } return true; }
@Test public void testMultiLineMatching() { // enable info logging because only error is enabled by default TestLoggerFactory loggerFactory = Settings.instance().enable(LogLevel.InfoLevel).buildLogging(); TestLogger logger = loggerFactory.getLogger(this.getClass()); // do some multiline logging logger.info("Line1" + System.lineSeparator() + "Line2"); // this one does match multiline logging assert (loggerFactory.matches("Line1.*")); // using DOTALL we can match multiline Pattern regex = Pattern.compile("Line1.*", Pattern.DOTALL); Pattern regexNoMatch = Pattern.compile("NOMATCH"); assert (loggerFactory.matches(regex)); assert (!loggerFactory.matches(regexNoMatch)); assert (loggerFactory.matches(LogLevel.InfoLevel, regex)); assert (!loggerFactory.matches(LogLevel.ErrorLevel, regex)); assert (logger.matches(regex)); assert (!logger.matches(regexNoMatch)); assert (logger.matches(LogLevel.InfoLevel, regex)); assert (!logger.matches(LogLevel.ErrorLevel, regex)); }
@Test public void testDemoAssemblyInjection() { // enable info logging because only error is enabled by default TestLoggerFactory loggingImpl = Settings.instance(). enable(LogLevel.InfoLevel).buildLogging(); // create the Assembly component along with its internal internalDetail instance Example assembly = new Example(loggingImpl); assembly.doSomeInfoLogging(); // check the Info logging assert (loggingImpl.matches("Hello from Assembly")); assert (loggingImpl.matches("Hello from InternalSubcomponent")); } }