Skip to content

Commit

Permalink
- BREAKING: rename LogExtension to LogRecorder to better reflect …
Browse files Browse the repository at this point in the history
…responsibility
  • Loading branch information
Nylle committed May 18, 2023
1 parent fdb8a66 commit 39e0f17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,34 @@ Logsert helps to test logging functionality by recording log-events during test-
<dependency>
<groupId>com.github.nylle</groupId>
<artifactId>logsert</artifactId>
<version>0.0.1</version>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
```

## Usage
```java
class SomethingThatLogsTest {

@RegisterExtension
LoggerExtension logger = new LoggerExtension(SomethingThatLogs.class);
LogRecorder logRecorder = new LogRecorder(SomethingThatLogs.class);

@Test
void fluentAssertionsAreConvenient() {
var sut = new SomethingThatLogs();

sut.logInfoWithMdcAndException("message", Map.of("key", "value", "foo", "bar"), new RuntimeException("expected for test"));
var expectedException = new RuntimeException("expected for test");

sut.logInfoWithMdcAndException("message", Map.of("key", "value", "foo", "bar"), expectedException);

assertThat(logger).containsLogs()
assertThat(logRecorder).containsLogs(1)
.withMessage("message")
.withMessageContaining("essa")
.withLevel(Level.INFO)
.withMdcEntry("foo", "bar")
.withMdcEntry("key", "value")
.withMdcEntries(Map.of("key", "value"))
.withMdcEntries(Map.of("foo", "bar"))
.withMdcEntries(Map.of("key", "value", "foo", "bar"))
.withMdcEntriesExactly(Map.of("key", "value", "foo", "bar"))
.withException(expectedException)
.withException(RuntimeException.class)
Expand All @@ -49,7 +50,7 @@ class SomethingThatLogsTest {
var sut = new SomethingThatLogs();
sut.logInfoWithMdcAndException("message", Map.of("key", "value"), new RuntimeException("expected for test"));

assertThat(logger.getLogEvents())
assertThat(logRecorder.getLogEvents())
.extracting("level", "message", "MDCPropertyMap", "throwableProxy.className", "throwableProxy.message")
.contains(tuple(Level.INFO, "message", Map.of("key", "value"), RuntimeException.class.getName(), "expected for test"));
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.github.nylle</groupId>
<artifactId>logsert</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>
<version>1.0.0</version>

<name>Logsert</name>
<url>https://github.com/Nylle/Logsert</url>
Expand Down

0 comments on commit 39e0f17

Please sign in to comment.