Filling out ReverseComparator testing

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1160015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2011-08-21 17:26:36 +00:00
parent 07f1732b2f
commit c7d0111a2a
1 changed files with 35 additions and 0 deletions

View File

@ -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));
}
}