KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > collections > UnorderedCollectionComparerTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.test.collections;
5
6 /**
7  * Unit test for {@link UnorderedCollectionComparer}.
8  */

9 public class UnorderedCollectionComparerTest extends CollectionComparerTestBase {
10
11   public void setUp() throws Exception JavaDoc {
12     super.setUp();
13     this.comparer = new UnorderedCollectionComparer(this.equalityComparator, this.describer);
14   }
15
16   public void testDoesNotCheckOrder() throws Exception JavaDoc {
17     MyObj one = new MyObj("a");
18     MyObj two = new MyObj("b");
19
20     checkMismatches(NO_MISMATCHES, this.comparer.getMismatches(new Object JavaDoc[] { one, two, new MyObj("c") }, new Object JavaDoc[] {
21         two, one, new MyObj("c") }));
22   }
23
24   public void testChecksCounts() throws Exception JavaDoc {
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 JavaDoc[] { one, one, two, new MyObj("c") }, new Object JavaDoc[] { two, two, one, new MyObj("c") }));
31   }
32
33   public void testUsesEqualityComparator() throws Exception JavaDoc {
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 JavaDoc[] { uppercase }, new Object JavaDoc[] { lowercase }));
41
42     CASE_INSENSITIVE = true;
43
44     checkMismatches(NO_MISMATCHES, this.comparer.getMismatches(new Object JavaDoc[] { uppercase }, new Object JavaDoc[] { 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 JavaDoc[] { uppercase }, new Object JavaDoc[] { lowercase }));
50   }
51
52   public void testDifferentObjectTypes() throws Exception JavaDoc {
53     Object JavaDoc oneObj = new MyObj("foo");
54     Object JavaDoc 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 JavaDoc[] { oneObj }, new Object JavaDoc[] { 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 JavaDoc[] { twoObj }, new Object JavaDoc[] { oneObj }));
63   }
64
65   public void testMultipleProblems() throws Exception JavaDoc {
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 JavaDoc[] one = new Object JavaDoc[] { firstZero, bothOne, firstTwo, bothThree };
75     Object JavaDoc[] two = new Object JavaDoc[] { 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