Add samples to show using Flogger in JUnit
- Dominant language
- Java
- Stars
- 1.5k
- Forks
- 133
- Avg merge
- 6m
- Merged PRs (30d)
- 7
Description
As part of unit testing, it becomes important to test the Logged messages in case of exceptions or other such scenarios.
Is this the recommended way to test logging behaviour in tests?
```java
@Test
public void read_invalidPath_logsError() {
Handler mockHandler = Mockito.mock(Handler.class);
ArgumentCaptor logRecordCaptor = ArgumentCaptor.forClass(LogRecord.class);
//set mock handler with Argument Captor
Logger.getLogger(JsonMessageParser.class.getName()).addHandler(mockHandler);
JsonMessageParser.of(TEST_JSON).read("$.code2");
verify(mockHandler).publish(logRecordCaptor.capture());
assertThat(logRecordCaptor.getValue().getMessage()).contains("error reading [$.code2]");
}
```
Contributor guide
Assessment
This issue has not been assessed yet.