1 4 package com.tc.test.collections; 5 6 9 public class UnorderedCollectionComparerTest extends CollectionComparerTestBase { 10 11 public void setUp() throws Exception { 12 super.setUp(); 13 this.comparer = new UnorderedCollectionComparer(this.equalityComparator, this.describer); 14 } 15 16 public void testDoesNotCheckOrder() throws Exception { 17 MyObj one = new MyObj("a"); 18 MyObj two = new MyObj("b"); 19 20 checkMismatches(NO_MISMATCHES, this.comparer.getMismatches(new Object [] { one, two, new MyObj("c") }, new Object [] { 21 two, one, new MyObj("c") })); 22 } 23 24 public void testChecksCounts() throws Exception { 25 MyObj one = new MyObj("a"); 26 MyObj two = new MyObj("b"); 27 28 checkMismatches(new CollectionMismatch[] { new UnequalObjectCountCollectionMismatch(one, 0, 2, 1, this.describer), 29 new UnequalObjectCountCollectionMismatch(two, 2, 1, 2, this.describer) }, this.comparer 30 .getMismatches(new Object [] { one, one, two, new MyObj("c") }, new Object [] { two, two, one, new MyObj("c") })); 31 } 32 33 public void testUsesEqualityComparator() throws Exception { 34 MyObj uppercase = new MyObj("FOO"); 35 MyObj lowercase = new MyObj("foo"); 36 37 CASE_INSENSITIVE = false; 38 checkMismatches(new CollectionMismatch[] { new MissingObjectCollectionMismatch(uppercase, true, 0, this.describer), 39 new MissingObjectCollectionMismatch(lowercase, false, 0, this.describer) }, this.comparer 40 .getMismatches(new Object [] { uppercase }, new Object [] { lowercase })); 41 42 CASE_INSENSITIVE = true; 43 44 checkMismatches(NO_MISMATCHES, this.comparer.getMismatches(new Object [] { uppercase }, new Object [] { lowercase })); 45 46 CASE_INSENSITIVE = false; 47 checkMismatches(new CollectionMismatch[] { new MissingObjectCollectionMismatch(uppercase, true, 0, this.describer), 48 new MissingObjectCollectionMismatch(lowercase, false, 0, this.describer) }, this.comparer 49 .getMismatches(new Object [] { uppercase }, new Object [] { lowercase })); 50 } 51 52 public void testDifferentObjectTypes() throws Exception { 53 Object oneObj = new MyObj("foo"); 54 Object twoObj = "foo"; 55 56 checkMismatches(new CollectionMismatch[] { new MissingObjectCollectionMismatch(oneObj, true, 0, this.describer), 57 new MissingObjectCollectionMismatch(twoObj, false, 0, this.describer) }, this.comparer 58 .getMismatches(new Object [] { oneObj }, new Object [] { twoObj })); 59 60 checkMismatches(new CollectionMismatch[] { new MissingObjectCollectionMismatch(twoObj, true, 0, this.describer), 61 new MissingObjectCollectionMismatch(oneObj, false, 0, this.describer) }, this.comparer 62 .getMismatches(new Object [] { twoObj }, new Object [] { oneObj })); 63 } 64 65 public void testMultipleProblems() throws Exception { 66 MyObj firstZero = new MyObj("a"); 67 MyObj secondZero = new MyObj("x"); 68 MyObj bothOne = new MyObj("b"); 69 MyObj firstTwo = new MyObj("c"); 70 MyObj secondTwo = new MyObj("y"); 71 MyObj bothThree = new MyObj("d"); 72 MyObj secondFour = new MyObj("q"); 73 74 Object [] one = new Object [] { firstZero, bothOne, firstTwo, bothThree }; 75 Object [] two = new Object [] { secondZero, bothOne, secondTwo, bothThree, secondFour }; 76 77 CollectionMismatch[] expectedMismatches = new CollectionMismatch[] { 78 new MissingObjectCollectionMismatch(firstZero, true, 0, this.describer), 79 new MissingObjectCollectionMismatch(firstTwo, true, 2, this.describer), 80 new MissingObjectCollectionMismatch(secondZero, false, 0, this.describer), 81 new MissingObjectCollectionMismatch(secondTwo, false, 2, this.describer), 82 new MissingObjectCollectionMismatch(secondFour, false, 4, this.describer) }; 83 84 checkMismatches(expectedMismatches, this.comparer.getMismatches(one, two)); 85 } 86 87 } | Popular Tags |