Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggerMocker would be nice to have #116

Open
yegor256 opened this issue Apr 30, 2012 · 1 comment
Open

LoggerMocker would be nice to have #116

yegor256 opened this issue Apr 30, 2012 · 1 comment

Comments

@yegor256
Copy link
Member

Would be nice to have LoggerMocker class, which can catch all logging messages and enable assertions on them.

Something like this:

@Test
public void testSomeCode() {
  final LoggerMocker log = new LoggerMocker().mock();
  // some code
  log.expect(MyClass.class)
    .info("works fine at this moment")
    .expect(SomeOtherClass.class)
    .error("some defect")
    .show();
}
@yegor256
Copy link
Member Author

it's better to create jcabi-matchers-slf4j module, which will do something like this:

@Test
public void testSomeCode() {
  final Slf4jCapture capture = new Slf4jCapture();
  // some code
  MatcherAssert.assertThat(
    capture, // collection of slf4j events
    Matchers.hasItem(
      Matchers.allOf(
        Log4jMatchers.hasLevel(Level.INFO),
        Log4jMatchers.hasMessage(Matchers.containsString("test"))
      )
    )
  );
}

@yegor256 yegor256 transferred this issue from jcabi/jcabi Sep 10, 2022
@yegor256 yegor256 removed their assignment Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant