001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.util;
005:
006: import com.tc.test.TCTestCase;
007:
008: /**
009: * Unit test for {@link EqualsEqualityComparator}.
010: */
011: public class EqualsEqualityComparatorTest extends TCTestCase {
012:
013: private static boolean CASE_INSENSITIVE = false;
014:
015: public static class MyObj {
016: private final String value;
017:
018: public MyObj(String value) {
019: this .value = value;
020: }
021:
022: public boolean equals(Object that) {
023: if (this == that)
024: return true;
025: if (!(that instanceof MyObj))
026: return false;
027:
028: if (CASE_INSENSITIVE)
029: return this .value
030: .equalsIgnoreCase(((MyObj) that).value);
031: else
032: return this .value.equals(((MyObj) that).value);
033: }
034: }
035:
036: public void testNull() {
037: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(null,
038: null));
039: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals("foo",
040: null));
041: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(null,
042: "foo"));
043: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(null,
044: new Integer(0)));
045: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(
046: new Integer(0), null));
047: }
048:
049: public void testObjects() {
050: MyObj one = new MyObj("foo");
051: MyObj two = new MyObj("foo");
052: MyObj three = new MyObj("Foo");
053: MyObj four = new MyObj("Foo");
054:
055: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(one, two));
056: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(two, one));
057: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(three,
058: four));
059: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(four,
060: three));
061:
062: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(one,
063: three));
064: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(three,
065: one));
066: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(one,
067: four));
068: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(four,
069: one));
070: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(two,
071: three));
072: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(three,
073: two));
074: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(two,
075: four));
076: assertFalse(EqualsEqualityComparator.INSTANCE.isEquals(four,
077: two));
078:
079: CASE_INSENSITIVE = true;
080:
081: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(one, two));
082: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(two, one));
083: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(three,
084: four));
085: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(four,
086: three));
087:
088: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(one,
089: three));
090: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(three,
091: one));
092: assertTrue(EqualsEqualityComparator.INSTANCE
093: .isEquals(one, four));
094: assertTrue(EqualsEqualityComparator.INSTANCE
095: .isEquals(four, one));
096: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(two,
097: three));
098: assertTrue(EqualsEqualityComparator.INSTANCE.isEquals(three,
099: two));
100: assertTrue(EqualsEqualityComparator.INSTANCE
101: .isEquals(two, four));
102: assertTrue(EqualsEqualityComparator.INSTANCE
103: .isEquals(four, two));
104: }
105:
106: }
|