Skip to content

Commit

Permalink
Tests chain resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Apr 26, 2018
1 parent cdde0e5 commit 3384570
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/test/java/com/obsidiandynamics/zerolog/ZlgImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ public void testLogInfoWithTagAndException() {
}

/**
* Tests logging at info level with all argument types.
* Tests logging at info level with all argument types. The first pass uses all argument types;
* the second pass is used to verify that the thread-local chain is reset correctly after flushing.
*/
@Test
public void testLogInfoWithAllArgTypes() {
final LogMocks mocks = new LogMocks(LogLevel.CONF, LogLevel.INFO);
final Zlg zlg = Zlg.forName("test").withConfigService(mocks).get();
final String format = "message";
final String firstMessage = "message";
final Exception exception = new Exception("test exception");

zlg
.level(LogLevel.INFO)
.format(format)
.format(firstMessage)
.arg(true)
.arg((byte) 0x01)
.arg('c')
Expand All @@ -123,11 +125,25 @@ public void testLogInfoWithAllArgTypes() {
.arg(42L)
.arg("string")
.arg((short) 42)
.threw(exception)
.entrypoint("entrypoint")
.log();
verify(mocks.target).isEnabled(eq(LogLevel.INFO));
verify(mocks.target)
.log(eq(LogLevel.INFO), isNull(), eq(format), eq(9), any(), isNull(), eq(LogChain.ENTRYPOINT));
.log(eq(LogLevel.INFO), isNull(), eq(firstMessage), eq(9), any(), eq(exception), eq("entrypoint"));
assertArrayEquals(new Object[] {true, (byte) 0x01, 'c', 3.14d, 3.14f, 42, 42L, "string", (short) 42}, mocks.argv);

// tests the resetting of the log chain
final String secondMessage = "another message";

zlg
.level(LogLevel.WARN)
.format(secondMessage)
.log();
verify(mocks.target).isEnabled(eq(LogLevel.WARN));
verify(mocks.target)
.log(eq(LogLevel.WARN), isNull(), eq(secondMessage), eq(0), any(), isNull(), eq(LogChain.ENTRYPOINT));
assertArrayEquals(new Object[0], mocks.argv);
}

/**
Expand Down

0 comments on commit 3384570

Please sign in to comment.