public void testGetAfterRemoveReturnsNull() { final String testKey = "hefty"; final Object testValue = new Object(); context.put(testKey, testValue); context.remove(testKey); assertNull("remove() should result in null value for get()", context.get(testKey)); }
@Test public void shouldPreserveOldEntriesFromTheMapWhenAutoClosed() throws Exception { final String oldValue = "oldValue"; ThreadContext.put(key, oldValue); try (final CloseableThreadContext ignored = CloseableThreadContext.put(key, value)) { assertThat(ThreadContext.get(key), is(value)); } assertThat(ThreadContext.get(key), is(oldValue)); }
@Test public void shouldNestEntries() throws Exception { final String oldValue = "oldValue"; final String innerValue = "innerValue"; ThreadContext.put(key, oldValue); try (final CloseableThreadContext ignored = CloseableThreadContext.put(key, value)) { assertThat(ThreadContext.get(key), is(value)); try (final CloseableThreadContext ignored2 = CloseableThreadContext.put(key, innerValue)) { assertThat(ThreadContext.get(key), is(innerValue)); } assertThat(ThreadContext.get(key), is(value)); } assertThat(ThreadContext.get(key), is(oldValue)); }
public void testClearRemovesMDCValue() { ThreadContext log4jThreadContext = ThreadContext.newMDCEnabledContext(); Hashtable mdcContext = MDC.getContext(); assertNull(mdcContext); final String testKey = "painter"; log4jThreadContext.put(testKey, 7); mdcContext = MDC.getContext(); assertEquals(1, mdcContext.size()); log4jThreadContext.clear(); assertEquals(0, mdcContext.size()); assertNull("get() after clear should return null", log4jThreadContext.get(testKey)); }
public void testClearRemovesValue() { final String testKey = "painter"; context.put(testKey, 7); context.clear(); assertNull("get() after clear should return null", context.get(testKey)); }
public void testGetRetrievesPutValue() { final String testKey = "brainy"; final Object testValue = new Object(); context.put(testKey, testValue); assertEquals(testValue, context.get(testKey)); }