logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1593090 - /logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
Date Wed, 07 May 2014 18:07:22 GMT
Author: ggregory
Date: Wed May  7 18:07:22 2014
New Revision: 1593090

URL: http://svn.apache.org/r1593090
Log:
Refactor common code.

Modified:
    logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java

Modified: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java?rev=1593090&r1=1593089&r2=1593090&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
Wed May  7 18:07:22 2014
@@ -65,13 +65,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testPopRemovesLastAddedItem() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
         assertEquals(3, stack.getDepth());
 
         assertEquals("msg3", stack.pop());
@@ -101,13 +95,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testTrim() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         stack.trim(1);
         assertEquals(1, stack.size());
@@ -116,13 +104,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testCopy() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         final ThreadContextStack copy = stack.copy();
         assertEquals(3, copy.size());
@@ -152,20 +134,16 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testClear() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         stack.clear();
         assertTrue(stack.isEmpty());
     }
 
-    @Test
-    public void testContains() {
+    /**
+     * @return
+     */
+    private DefaultThreadContextStack createStack() {
         final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
         stack.clear();
         assertTrue(stack.isEmpty());
@@ -173,6 +151,12 @@ public class DefaultThreadContextStackTe
         stack.add("msg2");
         stack.push("msg3");
         assertEquals(3, stack.size());
+        return stack;
+    }
+
+    @Test
+    public void testContains() {
+        final DefaultThreadContextStack stack = createStack();
 
         assertTrue(stack.contains("msg1"));
         assertTrue(stack.contains("msg2"));
@@ -181,13 +165,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testIteratorReturnsInListOrderNotStackOrder() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         final Iterator<String> iter = stack.iterator();
         assertTrue(iter.hasNext());
@@ -201,13 +179,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testToArray() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         final String[] expecteds = {"msg1", "msg2", "msg3"};
         assertArrayEquals(expecteds, stack.toArray());
@@ -215,13 +187,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testToArrayTArray() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         final String[] expecteds = {"msg1", "msg2", "msg3"};
         final String[] result = new String[3] ;
@@ -231,13 +197,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testRemove() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
         assertTrue(stack.containsAll(Arrays.asList("msg1", "msg2", "msg3")));
 
         stack.remove("msg1");
@@ -253,26 +213,14 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testContainsAll() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         assertTrue(stack.containsAll(Arrays.asList("msg1", "msg2", "msg3")));
     }
 
     @Test
     public void testAddAll() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         stack.addAll(Arrays.asList("msg4", "msg5"));
         assertEquals(5, stack.size());
@@ -285,13 +233,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testRemoveAll() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         stack.removeAll(Arrays.asList("msg1", "msg3"));
         assertEquals(1, stack.size());
@@ -302,13 +244,7 @@ public class DefaultThreadContextStackTe
 
     @Test
     public void testRetainAll() {
-        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final DefaultThreadContextStack stack = createStack();
 
         stack.retainAll(Arrays.asList("msg1", "msg3"));
         assertEquals(2, stack.size());



Mime
View raw message