@Test public void shouldPushAndPopAnEntryToTheStack() throws Exception { final String message = "message"; try (final CloseableThreadContext ignored = CloseableThreadContext.push(message)) { assertThat(ThreadContext.peek(), is(message)); } assertThat(ThreadContext.peek(), is("")); }
@Test public void shouldPushAndPopAParameterizedEntryToTheStack() throws Exception { final String parameterizedMessage = "message {}"; final String parameterizedMessageParameter = "param"; final String formattedMessage = parameterizedMessage.replace("{}", parameterizedMessageParameter); try (final CloseableThreadContext ignored = CloseableThreadContext.push(parameterizedMessage, parameterizedMessageParameter)) { assertThat(ThreadContext.peek(), is(formattedMessage)); } assertThat(ThreadContext.peek(), is("")); }