logging-commits mailing list archives

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

URL: http://svn.apache.org/r1593078
Log:
Implement equals() and hashCode(); for XML and JSON receiver testing.

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

Modified: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java?rev=1593078&r1=1593077&r2=1593078&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java
Wed May  7 17:41:41 2014
@@ -69,13 +69,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testPopRemovesLastAddedItem() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
         assertEquals(3, stack.getDepth());
 
         assertEquals("msg3", stack.pop());
@@ -105,13 +99,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testTrim() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         stack.trim(1);
         assertEquals(1, stack.size());
@@ -120,13 +108,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testCopy() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         final ThreadContextStack copy = stack.copy();
         assertEquals(3, copy.size());
@@ -156,27 +138,46 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testClear() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         stack.clear();
         assertTrue(stack.isEmpty());
     }
 
     @Test
+    public void testEquals() {
+        final MutableThreadContextStack stack1 = createList();
+        final MutableThreadContextStack stack2 = createList();
+        assertEquals(stack1, stack1);
+        assertEquals(stack2, stack2);
+        assertEquals(stack1, stack2);
+        assertEquals(stack2, stack1);
+    }
+
+    @Test
+    public void testHashCode() {
+        final MutableThreadContextStack stack1 = createList();
+        final MutableThreadContextStack stack2 = createList();
+        assertEquals(stack1.hashCode(), stack2.hashCode());
+    }
+
+    /**
+     * @return
+     */
+    private MutableThreadContextStack createList() {
+        final MutableThreadContextStack stack1 = new MutableThreadContextStack(new ArrayList<String>());
+        stack1.clear();
+        assertTrue(stack1.isEmpty());
+        stack1.push("msg1");
+        stack1.add("msg2");
+        stack1.push("msg3");
+        assertEquals(3, stack1.size());
+        return stack1;
+    }
+
+    @Test
     public void testContains() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         assertTrue(stack.contains("msg1"));
         assertTrue(stack.contains("msg2"));
@@ -185,13 +186,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testIteratorReturnsInListOrderNotStackOrder() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         final Iterator<String> iter = stack.iterator();
         assertTrue(iter.hasNext());
@@ -205,13 +200,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testToArray() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         final String[] expecteds = {"msg1", "msg2", "msg3"};
         assertArrayEquals(expecteds, stack.toArray());
@@ -219,13 +208,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testToArrayTArray() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         final String[] expecteds = {"msg1", "msg2", "msg3"};
         final String[] result = new String[3] ;
@@ -235,13 +218,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testRemove() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
         assertTrue(stack.containsAll(Arrays.asList("msg1", "msg2", "msg3")));
 
         stack.remove("msg1");
@@ -257,26 +234,14 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testContainsAll() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         assertTrue(stack.containsAll(Arrays.asList("msg1", "msg2", "msg3")));
     }
 
     @Test
     public void testAddAll() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         stack.addAll(Arrays.asList("msg4", "msg5"));
         assertEquals(5, stack.size());
@@ -289,13 +254,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testRemoveAll() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         stack.removeAll(Arrays.asList("msg1", "msg3"));
         assertEquals(1, stack.size());
@@ -306,13 +265,7 @@ public class MutableThreadContextStackTe
 
     @Test
     public void testRetainAll() {
-        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
-        stack.clear();
-        assertTrue(stack.isEmpty());
-        stack.push("msg1");
-        stack.add("msg2");
-        stack.push("msg3");
-        assertEquals(3, stack.size());
+        final MutableThreadContextStack stack = createList();
 
         stack.retainAll(Arrays.asList("msg1", "msg3"));
         assertEquals(2, stack.size());



Mime
View raw message