@Test public void testCopy() { final DefaultThreadContextStack stack = createStack(); final ThreadContextStack copy = stack.copy(); assertEquals(3, copy.size()); assertTrue(copy.containsAll(Arrays.asList("msg1", "msg2", "msg3"))); // clearing stack does not affect copy stack.clear(); assertTrue(stack.isEmpty()); assertEquals(3, copy.size()); // not affected assertTrue(copy.containsAll(Arrays.asList("msg1", "msg2", "msg3"))); // adding to copy does not affect stack copy.add("other"); assertEquals(4, copy.size()); // not affected assertTrue(stack.isEmpty()); // adding to stack does not affect copy stack.push("newStackMsg"); assertEquals(1, stack.size()); assertEquals(4, copy.size()); // not affected // clearing copy does not affect stack copy.clear(); assertTrue(copy.isEmpty()); assertEquals(1, stack.size()); }
@Test public void testCopy() { final MutableThreadContextStack stack = createStack(); final ThreadContextStack copy = stack.copy(); assertEquals(3, copy.size()); assertTrue(copy.containsAll(Arrays.asList("msg1", "msg2", "msg3"))); // clearing stack does not affect copy stack.clear(); assertTrue(stack.isEmpty()); assertEquals(3, copy.size()); // not affected assertTrue(copy.containsAll(Arrays.asList("msg1", "msg2", "msg3"))); // adding to copy does not affect stack copy.add("other"); assertEquals(4, copy.size()); // not affected assertTrue(stack.isEmpty()); // adding to stack does not affect copy stack.push("newStackMsg"); assertEquals(1, stack.size()); assertEquals(4, copy.size()); // not affected // clearing copy does not affect stack copy.clear(); assertTrue(copy.isEmpty()); assertEquals(1, stack.size()); }