Class LogCaptureRule

  • All Implemented Interfaces:
    TestRule

    public class LogCaptureRule
    extends Object
    implements TestRule
    JUnit Rule which "captures" slf4j-simple logs. By default, it fails the test if an error was logged. It can also pass the test if a logged error was expected (but fail it otherwise).

    Usage:

       public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule();
    
       @Test ...
    
           logRule.expectError();
     

    See also e.g. slf4j-test or slf4jtesting (both of which, contrary to this, don't integrate with slf4j-simple which we already widely use in ODL tests).

    Author:
    Michael Vorburger.ch
    See Also:
    ExpectedException
    • Constructor Detail

      • LogCaptureRule

        public LogCaptureRule()
    • Method Detail

      • expectLastErrorMessageContains

        public void expectLastErrorMessageContains​(String partialErrorMessage)
      • expectError

        public void expectError​(String message,
                                int howManyMessagesBack)
      • expectError

        public void expectError​(String message)
      • getLastErrorThrowable

        public Throwable getLastErrorThrowable()
      • getErrorThrowable

        public Throwable getErrorThrowable​(int howManyMessagesBack)