コード例 #1
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 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));
 }
コード例 #2
0
 @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));
 }
コード例 #3
0
 @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));
 }
コード例 #4
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
  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));
  }
コード例 #5
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testClearRemovesValue() {
   final String testKey = "painter";
   context.put(testKey, 7);
   context.clear();
   assertNull("get() after clear should return null", context.get(testKey));
 }
コード例 #6
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testGetRetrievesPutValue() {
   final String testKey = "brainy";
   final Object testValue = new Object();
   context.put(testKey, testValue);
   assertEquals(testValue, context.get(testKey));
 }