1public class FooServiceTest {
2
3 private LogCaptor logCaptor = LogCaptor.forClass(FooService.class);
4
5 @Test
6 public void logInfoAndWarnMessages() {
7 FooService fooService = new FooService();
8 fooService.sayHello();
9
10 assertThat(logCaptor.getWarnLogs())
11 .contains("Congratulations, you are pregnant!");
12 }
13}
14
1public class FooService {
2
3 private static final Logger LOGGER = LoggerFactory.getLogger(FooService.class);
4
5 public void sayHello() {
6 LOGGER.warn("Congratulations, you are pregnant!");
7 }
8
9}
10