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.test.collections;
005:
006: /**
007: * Unit test for {@link UnorderedCollectionComparer}.
008: */
009: public class UnorderedCollectionComparerTest extends
010: CollectionComparerTestBase {
011:
012: public void setUp() throws Exception {
013: super .setUp();
014: this .comparer = new UnorderedCollectionComparer(
015: this .equalityComparator, this .describer);
016: }
017:
018: public void testDoesNotCheckOrder() throws Exception {
019: MyObj one = new MyObj("a");
020: MyObj two = new MyObj("b");
021:
022: checkMismatches(NO_MISMATCHES, this .comparer.getMismatches(
023: new Object[] { one, two, new MyObj("c") },
024: new Object[] { two, one, new MyObj("c") }));
025: }
026:
027: public void testChecksCounts() throws Exception {
028: MyObj one = new MyObj("a");
029: MyObj two = new MyObj("b");
030:
031: checkMismatches(new CollectionMismatch[] {
032: new UnequalObjectCountCollectionMismatch(one, 0, 2, 1,
033: this .describer),
034: new UnequalObjectCountCollectionMismatch(two, 2, 1, 2,
035: this .describer) }, this .comparer.getMismatches(
036: new Object[] { one, one, two, new MyObj("c") },
037: new Object[] { two, two, one, new MyObj("c") }));
038: }
039:
040: public void testUsesEqualityComparator() throws Exception {
041: MyObj uppercase = new MyObj("FOO");
042: MyObj lowercase = new MyObj("foo");
043:
044: CASE_INSENSITIVE = false;
045: checkMismatches(new CollectionMismatch[] {
046: new MissingObjectCollectionMismatch(uppercase, true, 0,
047: this .describer),
048: new MissingObjectCollectionMismatch(lowercase, false,
049: 0, this .describer) }, this .comparer
050: .getMismatches(new Object[] { uppercase },
051: new Object[] { lowercase }));
052:
053: CASE_INSENSITIVE = true;
054:
055: checkMismatches(NO_MISMATCHES, this .comparer.getMismatches(
056: new Object[] { uppercase }, new Object[] { lowercase }));
057:
058: CASE_INSENSITIVE = false;
059: checkMismatches(new CollectionMismatch[] {
060: new MissingObjectCollectionMismatch(uppercase, true, 0,
061: this .describer),
062: new MissingObjectCollectionMismatch(lowercase, false,
063: 0, this .describer) }, this .comparer
064: .getMismatches(new Object[] { uppercase },
065: new Object[] { lowercase }));
066: }
067:
068: public void testDifferentObjectTypes() throws Exception {
069: Object oneObj = new MyObj("foo");
070: Object twoObj = "foo";
071:
072: checkMismatches(new CollectionMismatch[] {
073: new MissingObjectCollectionMismatch(oneObj, true, 0,
074: this .describer),
075: new MissingObjectCollectionMismatch(twoObj, false, 0,
076: this .describer) }, this .comparer.getMismatches(
077: new Object[] { oneObj }, new Object[] { twoObj }));
078:
079: checkMismatches(new CollectionMismatch[] {
080: new MissingObjectCollectionMismatch(twoObj, true, 0,
081: this .describer),
082: new MissingObjectCollectionMismatch(oneObj, false, 0,
083: this .describer) }, this .comparer.getMismatches(
084: new Object[] { twoObj }, new Object[] { oneObj }));
085: }
086:
087: public void testMultipleProblems() throws Exception {
088: MyObj firstZero = new MyObj("a");
089: MyObj secondZero = new MyObj("x");
090: MyObj bothOne = new MyObj("b");
091: MyObj firstTwo = new MyObj("c");
092: MyObj secondTwo = new MyObj("y");
093: MyObj bothThree = new MyObj("d");
094: MyObj secondFour = new MyObj("q");
095:
096: Object[] one = new Object[] { firstZero, bothOne, firstTwo,
097: bothThree };
098: Object[] two = new Object[] { secondZero, bothOne, secondTwo,
099: bothThree, secondFour };
100:
101: CollectionMismatch[] expectedMismatches = new CollectionMismatch[] {
102: new MissingObjectCollectionMismatch(firstZero, true, 0,
103: this .describer),
104: new MissingObjectCollectionMismatch(firstTwo, true, 2,
105: this .describer),
106: new MissingObjectCollectionMismatch(secondZero, false,
107: 0, this .describer),
108: new MissingObjectCollectionMismatch(secondTwo, false,
109: 2, this .describer),
110: new MissingObjectCollectionMismatch(secondFour, false,
111: 4, this.describer) };
112:
113: checkMismatches(expectedMismatches, this.comparer
114: .getMismatches(one, two));
115: }
116:
117: }
|