commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1160015 - /commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/compare/ReverseComparatorTest.java
Date Sun, 21 Aug 2011 17:26:36 GMT
Author: bayard
Date: Sun Aug 21 17:26:36 2011
New Revision: 1160015

URL: http://svn.apache.org/viewvc?rev=1160015&view=rev
Log:
Filling out ReverseComparator testing

Modified:
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/compare/ReverseComparatorTest.java

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/compare/ReverseComparatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/compare/ReverseComparatorTest.java?rev=1160015&r1=1160014&r2=1160015&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/compare/ReverseComparatorTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/compare/ReverseComparatorTest.java
Sun Aug 21 17:26:36 2011
@@ -49,4 +49,39 @@ public class ReverseComparatorTest {
         assertTrue("Comparison wasn't reversed", rc.compare( "aardvark", "baa" ) > 0 );
     }
 
+    @Test
+    public void testTwoCallsCancel() {
+        ReverseComparator rc = new ReverseComparator(new ReverseComparator());
+
+        // back to front tests
+        assertTrue("Reversal wasn't cancelled out", rc.compare( 1, 2 ) < 0 );
+        assertTrue("Reversal wasn't cancelled out", rc.compare( 2, 1 ) > 0 );
+        assertTrue("Reversal wasn't cancelled out", rc.compare( "aardvark", "baa" ) <
0 );
+        assertTrue("Reversal wasn't cancelled out", rc.compare( "baa", "aardvark" ) >
0 );
+    }
+
+    @Test
+    public void testEquality() {
+        ReverseComparator rc1 = new ReverseComparator();
+        ReverseComparator rc2 = new ReverseComparator(rc1);
+        ReverseComparator rc3 = new ReverseComparator(rc1);
+
+        // test same instance
+        assertTrue("Same instance wasn't equal", rc1.equals(rc1));
+        assertEquals("Equal instance has different hash code", rc1.hashCode(), rc1.hashCode());
+
+        // test null not equal
+        assertFalse("Null was equal", rc1.equals(null));
+
+        // test diff subcomparator not equal
+        assertFalse("Was equal despite different nested comparators", rc1.equals(rc2));
+
+        // test same subcomparator equal
+        assertTrue("Wasn't equal despite same nested comparator", rc2.equals(rc3));
+        assertEquals("Same subcomparator had different hash code", rc2.hashCode(), rc3.hashCode());
+
+        // test different type not equal
+        assertFalse("Was equal despite not being same class", rc1.equals(this));
+    }
+
 }



Mime
View raw message