ContextHolderFactory { static ContextHolder getLocalContextHolder() { return LOCAL_CONTEXT_HOLDER; }    }
@Test public void testLCRemoveNonExistKey() { testRemoveNonExistKey(getLocalContextHolder()); }
@Test public void testLCRemoveWrongOrder() { ContextHolder localContextHolder = getLocalContextHolder(); try { localContextHolder.let(KEY1, "key1"); localContextHolder.let(KEY2, "key2"); testLCRemoveWrongOrder(localContextHolder, KEY1); } finally { localContextHolder.remove(KEY2); localContextHolder.remove(KEY1); } }
@Test public void testLCLetAndRemove() { ContextHolder localContextHolder = getLocalContextHolder(); localContextHolder.let(KEY1, Thread.currentThread().getName() + KEY1); localContextHolder.let(KEY2, Thread.currentThread().getName() + KEY2); localContextHolder.let(KEY3, Thread.currentThread().getName() + KEY3); localContextHolder.let(KEY2, Thread.currentThread().getName() + KEY2 + KEY2); assertEquals(Contexts.local().apply(KEY1), Thread.currentThread().getName() + KEY1); assertEquals(Contexts.local().apply(KEY2), Thread.currentThread().getName() + KEY2 + KEY2); assertEquals(Contexts.local().apply(KEY3), Thread.currentThread().getName() + KEY3); localContextHolder.remove(KEY2); assertEquals(Contexts.local().apply(KEY1), Thread.currentThread().getName() + KEY1); assertEquals(Contexts.local().apply(KEY2), Thread.currentThread().getName() + KEY2); assertEquals(Contexts.local().apply(KEY3), Thread.currentThread().getName() + KEY3); localContextHolder.remove(KEY3); assertEquals(Contexts.local().apply(KEY1), Thread.currentThread().getName() + KEY1); assertEquals(Contexts.local().apply(KEY2), Thread.currentThread().getName() + KEY2); assertFalse(Contexts.local().get(KEY3).isDefined()); localContextHolder.remove(KEY2); assertEquals(Contexts.local().apply(KEY1), Thread.currentThread().getName() + KEY1); assertFalse(Contexts.local().get(KEY2).isDefined()); assertFalse(Contexts.local().get(KEY3).isDefined()); localContextHolder.remove(KEY1); assertFalse(Contexts.local().get(KEY1).isDefined()); assertFalse(Contexts.local().get(KEY2).isDefined()); assertFalse(Contexts.local().get(KEY3).isDefined()); }