KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > builder > CompareToBuilderTest


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.lang.builder;
17
18 import java.math.BigInteger JavaDoc;
19
20 import junit.framework.Test;
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23 import junit.textui.TestRunner;
24
25 /**
26  * Unit tests {@link org.apache.commons.lang.builder.CompareToBuilder}.
27  *
28  * @author <a HREF="mailto:sdowney@panix.com">Steve Downey</a>
29  * @author <a HREF="mailto:scolebourne@joda.org">Stephen Colebourne</a>
30  * @version $Id: CompareToBuilderTest.java 161244 2005-04-14 06:16:36Z ggregory $
31  */

32 public class CompareToBuilderTest extends TestCase {
33
34   public CompareToBuilderTest(String JavaDoc name) {
35     super(name);
36   }
37      public static void main(String JavaDoc[] args) {
38         TestRunner.run(suite());
39     }
40
41     public static Test suite() {
42         TestSuite suite = new TestSuite(CompareToBuilderTest.class);
43         suite.setName("CompareToBuilder Tests");
44         return suite;
45     }
46
47     protected void setUp() throws Exception JavaDoc {
48         super.setUp();
49     }
50
51     protected void tearDown() throws Exception JavaDoc {
52         super.tearDown();
53     }
54
55     //-----------------------------------------------------------------------
56

57     static class TestObject implements Comparable JavaDoc {
58         private int a;
59         public TestObject(int a) {
60             this.a = a;
61         }
62         public boolean equals(Object JavaDoc o) {
63             if (o == this) {
64                 return true;
65             }
66             if (!(o instanceof TestObject)) {
67                 return false;
68             }
69             TestObject rhs = (TestObject) o;
70             return (a == rhs.a);
71         }
72
73         public void setA(int a) {
74             this.a = a;
75         }
76
77         public int getA() {
78             return a;
79         }
80         public int compareTo(Object JavaDoc o) {
81             TestObject rhs = (TestObject) o;
82             return (a < rhs.a) ? -1 : (a > rhs.a) ? +1 : 0;
83         }
84     }
85
86     static class TestSubObject extends TestObject {
87         private int b;
88         public TestSubObject() {
89             super(0);
90         }
91         public TestSubObject(int a, int b) {
92             super(a);
93             this.b = b;
94         }
95         public boolean equals(Object JavaDoc o) {
96             if (o == this) {
97                 return true;
98             }
99             if (!(o instanceof TestSubObject)) {
100                 return false;
101             }
102             TestSubObject rhs = (TestSubObject) o;
103             return super.equals(o) && (b == rhs.b);
104         }
105     }
106
107     static class TestTransientSubObject extends TestObject {
108         private transient int t;
109         public TestTransientSubObject(int a, int t) {
110             super(a);
111             this.t = t;
112         }
113     }
114
115     public void testReflectionCompare() {
116         TestObject o1 = new TestObject(4);
117         TestObject o2 = new TestObject(4);
118         assertTrue(CompareToBuilder.reflectionCompare(o1, o1) == 0);
119         assertTrue(CompareToBuilder.reflectionCompare(o1, o2) == 0);
120         o2.setA(5);
121         assertTrue(CompareToBuilder.reflectionCompare(o1, o2) < 0);
122         assertTrue(CompareToBuilder.reflectionCompare(o2, o1) > 0);
123     }
124
125     public void testReflectionCompareEx1() {
126         TestObject o1 = new TestObject(4);
127         try {
128             CompareToBuilder.reflectionCompare(o1, null);
129         } catch (NullPointerException JavaDoc ex) {
130             return;
131         }
132         fail();
133     }
134
135     public void testReflectionCompareEx2() {
136         TestObject o1 = new TestObject(4);
137         Object JavaDoc o2 = new Object JavaDoc();
138         try {
139             CompareToBuilder.reflectionCompare(o1, o2);
140             fail();
141         } catch (ClassCastException JavaDoc ex) {}
142     }
143
144     public void testReflectionHierarchyCompare() {
145         testReflectionHierarchyCompare(false);
146     }
147     
148     public void testReflectionHierarchyCompareTransients() {
149         testReflectionHierarchyCompare(true);
150
151         TestTransientSubObject x;
152         TestTransientSubObject y;
153         TestTransientSubObject z;
154
155         x = new TestTransientSubObject(1, 1);
156         y = new TestTransientSubObject(2, 2);
157         z = new TestTransientSubObject(3, 3);
158         assertXYZCompareOrder(x, y, z, true);
159         
160         x = new TestTransientSubObject(1, 1);
161         y = new TestTransientSubObject(1, 2);
162         z = new TestTransientSubObject(1, 3);
163         assertXYZCompareOrder(x, y, z, true);
164     }
165     
166     private void assertXYZCompareOrder(Object JavaDoc x, Object JavaDoc y, Object JavaDoc z, boolean testTransients) {
167         assertTrue(0 == CompareToBuilder.reflectionCompare(x, x, testTransients));
168         assertTrue(0 == CompareToBuilder.reflectionCompare(y, y, testTransients));
169         assertTrue(0 == CompareToBuilder.reflectionCompare(z, z, testTransients));
170         
171         assertTrue(0 > CompareToBuilder.reflectionCompare(x, y, testTransients));
172         assertTrue(0 > CompareToBuilder.reflectionCompare(x, z, testTransients));
173         assertTrue(0 > CompareToBuilder.reflectionCompare(y, z, testTransients));
174         
175         assertTrue(0 < CompareToBuilder.reflectionCompare(y, x, testTransients));
176         assertTrue(0 < CompareToBuilder.reflectionCompare(z, x, testTransients));
177         assertTrue(0 < CompareToBuilder.reflectionCompare(z, y, testTransients));
178     }
179     
180     public void testReflectionHierarchyCompare(boolean testTransients) {
181         TestObject to1 = new TestObject(1);
182         TestObject to2 = new TestObject(2);
183         TestObject to3 = new TestObject(3);
184         TestSubObject tso1 = new TestSubObject(1, 1);
185         TestSubObject tso2 = new TestSubObject(2, 2);
186         TestSubObject tso3 = new TestSubObject(3, 3);
187         
188         assertReflectionCompareContract(to1, to1, to1, false);
189         assertReflectionCompareContract(to1, to2, to3, false);
190         assertReflectionCompareContract(tso1, tso1, tso1, false);
191         assertReflectionCompareContract(tso1, tso2, tso3, false);
192         assertReflectionCompareContract("1", "2", "3", false);
193         
194         assertTrue(0 != CompareToBuilder.reflectionCompare(tso1, new TestSubObject(1, 0), testTransients));
195         assertTrue(0 != CompareToBuilder.reflectionCompare(tso1, new TestSubObject(0, 1), testTransients));
196
197         // root class
198
assertXYZCompareOrder(to1, to2, to3, true);
199         // subclass
200
assertXYZCompareOrder(tso1, tso2, tso3, true);
201     }
202
203     /**
204      * See "Effective Java" under "Consider Implementing Comparable".
205      *
206      * @param x an object to compare
207      * @param y an object to compare
208      * @param z an object to compare
209      * @param testTransients Whether to include transients in the comparison
210      */

211     public void assertReflectionCompareContract(Object JavaDoc x, Object JavaDoc y, Object JavaDoc z, boolean testTransients) {
212
213         // signum
214
assertTrue(reflectionCompareSignum(x, y, testTransients) == -reflectionCompareSignum(y, x, testTransients));
215         
216         // transitive
217
if (CompareToBuilder.reflectionCompare(x, y, testTransients) > 0 && CompareToBuilder.reflectionCompare(y, z, testTransients) > 0){
218             assertTrue(CompareToBuilder.reflectionCompare(x, z, testTransients) > 0);
219         }
220         
221         // un-named
222
if (CompareToBuilder.reflectionCompare(x, y, testTransients) == 0) {
223             assertTrue(reflectionCompareSignum(x, z, testTransients) == -reflectionCompareSignum(y, z, testTransients));
224         }
225         
226         // strongly recommended but not strictly required
227
assertTrue((CompareToBuilder.reflectionCompare(x, y, testTransients) ==0 ) == EqualsBuilder.reflectionEquals(x, y, testTransients));
228     }
229     
230     /**
231      * Returns the signum of the result of comparing x and y with
232      * <code>CompareToBuilder.reflectionCompare</code>
233      *
234      * @param lhs The "left-hand-side" of the comparison.
235      * @param rhs The "right-hand-side" of the comparison.
236      * @param testTransients Whether to include transients in the comparison
237      * @return int The signum
238      */

239     private int reflectionCompareSignum(Object JavaDoc lhs, Object JavaDoc rhs, boolean testTransients) {
240         return BigInteger.valueOf(CompareToBuilder.reflectionCompare(lhs, rhs, testTransients)).signum();
241     }
242     
243     public void testAppendSuper() {
244         TestObject o1 = new TestObject(4);
245         TestObject o2 = new TestObject(5);
246         assertTrue(new CompareToBuilder().appendSuper(0).append(o1, o1).toComparison() == 0);
247         assertTrue(new CompareToBuilder().appendSuper(0).append(o1, o2).toComparison() < 0);
248         assertTrue(new CompareToBuilder().appendSuper(0).append(o2, o1).toComparison() > 0);
249         
250         assertTrue(new CompareToBuilder().appendSuper(-1).append(o1, o1).toComparison() < 0);
251         assertTrue(new CompareToBuilder().appendSuper(-1).append(o1, o2).toComparison() < 0);
252         
253         assertTrue(new CompareToBuilder().appendSuper(1).append(o1, o1).toComparison() > 0);
254         assertTrue(new CompareToBuilder().appendSuper(1).append(o1, o2).toComparison() > 0);
255     }
256     
257     public void testObject() {
258         TestObject o1 = new TestObject(4);
259         TestObject o2 = new TestObject(4);
260         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
261         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() == 0);
262         o2.setA(5);
263         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
264         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
265         
266         assertTrue(new CompareToBuilder().append(o1, null).toComparison() > 0);
267         assertTrue(new CompareToBuilder().append((Object JavaDoc) null, (Object JavaDoc) null).toComparison() == 0);
268         assertTrue(new CompareToBuilder().append(null, o1).toComparison() < 0);
269     }
270
271     public void testObjectEx2() {
272         TestObject o1 = new TestObject(4);
273         Object JavaDoc o2 = new Object JavaDoc();
274         try {
275             new CompareToBuilder().append(o1, o2);
276             fail();
277         } catch (ClassCastException JavaDoc ex) {}
278     }
279
280     public void testObjectComparator() {
281         String JavaDoc o1 = "Fred";
282         String JavaDoc o2 = "Fred";
283         assertTrue(new CompareToBuilder().append(o1, o1, String.CASE_INSENSITIVE_ORDER).toComparison() == 0);
284         assertTrue(new CompareToBuilder().append(o1, o2, String.CASE_INSENSITIVE_ORDER).toComparison() == 0);
285         o2 = "FRED";
286         assertTrue(new CompareToBuilder().append(o1, o2, String.CASE_INSENSITIVE_ORDER).toComparison() == 0);
287         assertTrue(new CompareToBuilder().append(o2, o1, String.CASE_INSENSITIVE_ORDER).toComparison() == 0);
288         o2 = "FREDA";
289         assertTrue(new CompareToBuilder().append(o1, o2, String.CASE_INSENSITIVE_ORDER).toComparison() < 0);
290         assertTrue(new CompareToBuilder().append(o2, o1, String.CASE_INSENSITIVE_ORDER).toComparison() > 0);
291         
292         assertTrue(new CompareToBuilder().append(o1, null, String.CASE_INSENSITIVE_ORDER).toComparison() > 0);
293         assertTrue(new CompareToBuilder().append((Object JavaDoc) null, (Object JavaDoc) null, String.CASE_INSENSITIVE_ORDER).toComparison() == 0);
294         assertTrue(new CompareToBuilder().append(null, o1, String.CASE_INSENSITIVE_ORDER).toComparison() < 0);
295     }
296     
297     public void testObjectComparatorNull() {
298         String JavaDoc o1 = "Fred";
299         String JavaDoc o2 = "Fred";
300         assertTrue(new CompareToBuilder().append(o1, o1, null).toComparison() == 0);
301         assertTrue(new CompareToBuilder().append(o1, o2, null).toComparison() == 0);
302         o2 = "Zebra";
303         assertTrue(new CompareToBuilder().append(o1, o2, null).toComparison() < 0);
304         assertTrue(new CompareToBuilder().append(o2, o1, null).toComparison() > 0);
305         
306         assertTrue(new CompareToBuilder().append(o1, null, null).toComparison() > 0);
307         assertTrue(new CompareToBuilder().append((Object JavaDoc) null, (Object JavaDoc) null, null).toComparison() == 0);
308         assertTrue(new CompareToBuilder().append(null, o1, null).toComparison() < 0);
309     }
310
311     public void testLong() {
312         long o1 = 1L;
313         long o2 = 2L;
314         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
315         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
316         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
317         assertTrue(new CompareToBuilder().append(o1, Long.MAX_VALUE).toComparison() < 0);
318         assertTrue(new CompareToBuilder().append(Long.MAX_VALUE, o1).toComparison() > 0);
319         assertTrue(new CompareToBuilder().append(o1, Long.MIN_VALUE).toComparison() > 0);
320         assertTrue(new CompareToBuilder().append(Long.MIN_VALUE, o1).toComparison() < 0);
321     }
322
323     public void testInt() {
324         int o1 = 1;
325         int o2 = 2;
326         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
327         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
328         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
329         assertTrue(new CompareToBuilder().append(o1, Integer.MAX_VALUE).toComparison() < 0);
330         assertTrue(new CompareToBuilder().append(Integer.MAX_VALUE, o1).toComparison() > 0);
331         assertTrue(new CompareToBuilder().append(o1, Integer.MIN_VALUE).toComparison() > 0);
332         assertTrue(new CompareToBuilder().append(Integer.MIN_VALUE, o1).toComparison() < 0);
333     }
334
335     public void testShort() {
336         short o1 = 1;
337         short o2 = 2;
338         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
339         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
340         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
341         assertTrue(new CompareToBuilder().append(o1, Short.MAX_VALUE).toComparison() < 0);
342         assertTrue(new CompareToBuilder().append(Short.MAX_VALUE, o1).toComparison() > 0);
343         assertTrue(new CompareToBuilder().append(o1, Short.MIN_VALUE).toComparison() > 0);
344         assertTrue(new CompareToBuilder().append(Short.MIN_VALUE, o1).toComparison() < 0);
345     }
346
347     public void testChar() {
348         char o1 = 1;
349         char o2 = 2;
350         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
351         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
352         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
353         assertTrue(new CompareToBuilder().append(o1, Character.MAX_VALUE).toComparison() < 0);
354         assertTrue(new CompareToBuilder().append(Character.MAX_VALUE, o1).toComparison() > 0);
355         assertTrue(new CompareToBuilder().append(o1, Character.MIN_VALUE).toComparison() > 0);
356         assertTrue(new CompareToBuilder().append(Character.MIN_VALUE, o1).toComparison() < 0);
357     }
358
359     public void testByte() {
360         byte o1 = 1;
361         byte o2 = 2;
362         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
363         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
364         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
365         assertTrue(new CompareToBuilder().append(o1, Byte.MAX_VALUE).toComparison() < 0);
366         assertTrue(new CompareToBuilder().append(Byte.MAX_VALUE, o1).toComparison() > 0);
367         assertTrue(new CompareToBuilder().append(o1, Byte.MIN_VALUE).toComparison() > 0);
368         assertTrue(new CompareToBuilder().append(Byte.MIN_VALUE, o1).toComparison() < 0);
369     }
370
371     public void testDouble() {
372         double o1 = 1;
373         double o2 = 2;
374         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
375         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
376         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
377         assertTrue(new CompareToBuilder().append(o1, Double.MAX_VALUE).toComparison() < 0);
378         assertTrue(new CompareToBuilder().append(Double.MAX_VALUE, o1).toComparison() > 0);
379         assertTrue(new CompareToBuilder().append(o1, Double.MIN_VALUE).toComparison() > 0);
380         assertTrue(new CompareToBuilder().append(Double.MIN_VALUE, o1).toComparison() < 0);
381         assertTrue(new CompareToBuilder().append(Double.NaN, Double.NaN).toComparison() == 0);
382         assertTrue(new CompareToBuilder().append(Double.NaN, Double.MAX_VALUE).toComparison() > 0);
383         assertTrue(new CompareToBuilder().append(Double.POSITIVE_INFINITY, Double.MAX_VALUE).toComparison() > 0);
384         assertTrue(new CompareToBuilder().append(Double.NEGATIVE_INFINITY, Double.MIN_VALUE).toComparison() < 0);
385         assertTrue(new CompareToBuilder().append(o1, Double.NaN).toComparison() < 0);
386         assertTrue(new CompareToBuilder().append(Double.NaN, o1).toComparison() > 0);
387         assertTrue(new CompareToBuilder().append(-0.0, 0.0).toComparison() < 0);
388         assertTrue(new CompareToBuilder().append(0.0, -0.0).toComparison() > 0);
389     }
390
391     public void testFloat() {
392         float o1 = 1;
393         float o2 = 2;
394         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
395         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() < 0);
396         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() > 0);
397         assertTrue(new CompareToBuilder().append(o1, Float.MAX_VALUE).toComparison() < 0);
398         assertTrue(new CompareToBuilder().append(Float.MAX_VALUE, o1).toComparison() > 0);
399         assertTrue(new CompareToBuilder().append(o1, Float.MIN_VALUE).toComparison() > 0);
400         assertTrue(new CompareToBuilder().append(Float.MIN_VALUE, o1).toComparison() < 0);
401         assertTrue(new CompareToBuilder().append(Float.NaN, Float.NaN).toComparison() == 0);
402         assertTrue(new CompareToBuilder().append(Float.NaN, Float.MAX_VALUE).toComparison() > 0);
403         assertTrue(new CompareToBuilder().append(Float.POSITIVE_INFINITY, Float.MAX_VALUE).toComparison() > 0);
404         assertTrue(new CompareToBuilder().append(Float.NEGATIVE_INFINITY, Float.MIN_VALUE).toComparison() < 0);
405         assertTrue(new CompareToBuilder().append(o1, Float.NaN).toComparison() < 0);
406         assertTrue(new CompareToBuilder().append(Float.NaN, o1).toComparison() > 0);
407         assertTrue(new CompareToBuilder().append(-0.0, 0.0).toComparison() < 0);
408         assertTrue(new CompareToBuilder().append(0.0, -0.0).toComparison() > 0);
409     }
410
411     public void testBoolean() {
412         boolean o1 = true;
413         boolean o2 = false;
414         assertTrue(new CompareToBuilder().append(o1, o1).toComparison() == 0);
415         assertTrue(new CompareToBuilder().append(o2, o2).toComparison() == 0);
416         assertTrue(new CompareToBuilder().append(o1, o2).toComparison() > 0);
417         assertTrue(new CompareToBuilder().append(o2, o1).toComparison() < 0);
418     }
419
420     public void testObjectArray() {
421         TestObject[] obj1 = new TestObject[2];
422         obj1[0] = new TestObject(4);
423         obj1[1] = new TestObject(5);
424         TestObject[] obj2 = new TestObject[2];
425         obj2[0] = new TestObject(4);
426         obj2[1] = new TestObject(5);
427         TestObject[] obj3 = new TestObject[3];
428         obj3[0] = new TestObject(4);
429         obj3[1] = new TestObject(5);
430         obj3[2] = new TestObject(6);
431         
432         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
433         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
434         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
435         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
436         
437         obj1[1] = new TestObject(7);
438         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
439         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
440
441         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
442         assertTrue(new CompareToBuilder().append((Object JavaDoc[]) null, (Object JavaDoc[]) null).toComparison() == 0);
443         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
444     }
445
446     public void testLongArray() {
447         long[] obj1 = new long[2];
448         obj1[0] = 5L;
449         obj1[1] = 6L;
450         long[] obj2 = new long[2];
451         obj2[0] = 5L;
452         obj2[1] = 6L;
453         long[] obj3 = new long[3];
454         obj3[0] = 5L;
455         obj3[1] = 6L;
456         obj3[2] = 7L;
457         
458         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
459         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
460         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
461         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
462
463         obj1[1] = 7;
464         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
465         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
466
467         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
468         assertTrue(new CompareToBuilder().append((long[]) null, (long[]) null).toComparison() == 0);
469         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
470     }
471
472     public void testIntArray() {
473         int[] obj1 = new int[2];
474         obj1[0] = 5;
475         obj1[1] = 6;
476         int[] obj2 = new int[2];
477         obj2[0] = 5;
478         obj2[1] = 6;
479         int[] obj3 = new int[3];
480         obj3[0] = 5;
481         obj3[1] = 6;
482         obj3[2] = 7;
483
484         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
485         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
486         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
487         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
488
489         obj1[1] = 7;
490         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
491         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
492
493         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
494         assertTrue(new CompareToBuilder().append((int[]) null, (int[]) null).toComparison() == 0);
495         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
496     }
497
498     public void testShortArray() {
499         short[] obj1 = new short[2];
500         obj1[0] = 5;
501         obj1[1] = 6;
502         short[] obj2 = new short[2];
503         obj2[0] = 5;
504         obj2[1] = 6;
505         short[] obj3 = new short[3];
506         obj3[0] = 5;
507         obj3[1] = 6;
508         obj3[2] = 7;
509
510         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
511         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
512         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
513         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
514
515         obj1[1] = 7;
516         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
517         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
518
519         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
520         assertTrue(new CompareToBuilder().append((short[]) null, (short[]) null).toComparison() == 0);
521         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
522     }
523
524     public void testCharArray() {
525         char[] obj1 = new char[2];
526         obj1[0] = 5;
527         obj1[1] = 6;
528         char[] obj2 = new char[2];
529         obj2[0] = 5;
530         obj2[1] = 6;
531         char[] obj3 = new char[3];
532         obj3[0] = 5;
533         obj3[1] = 6;
534         obj3[2] = 7;
535
536         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
537         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
538         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
539         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
540
541         obj1[1] = 7;
542         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
543         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
544
545         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
546         assertTrue(new CompareToBuilder().append((char[]) null, (char[]) null).toComparison() == 0);
547         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
548     }
549
550     public void testByteArray() {
551         byte[] obj1 = new byte[2];
552         obj1[0] = 5;
553         obj1[1] = 6;
554         byte[] obj2 = new byte[2];
555         obj2[0] = 5;
556         obj2[1] = 6;
557         byte[] obj3 = new byte[3];
558         obj3[0] = 5;
559         obj3[1] = 6;
560         obj3[2] = 7;
561
562         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
563         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
564         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
565         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
566
567         obj1[1] = 7;
568         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
569         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
570
571         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
572         assertTrue(new CompareToBuilder().append((byte[]) null, (byte[]) null).toComparison() == 0);
573         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
574     }
575
576     public void testDoubleArray() {
577         double[] obj1 = new double[2];
578         obj1[0] = 5;
579         obj1[1] = 6;
580         double[] obj2 = new double[2];
581         obj2[0] = 5;
582         obj2[1] = 6;
583         double[] obj3 = new double[3];
584         obj3[0] = 5;
585         obj3[1] = 6;
586         obj3[2] = 7;
587
588         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
589         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
590         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
591         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
592
593         obj1[1] = 7;
594         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
595         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
596
597         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
598         assertTrue(new CompareToBuilder().append((double[]) null, (double[]) null).toComparison() == 0);
599         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
600     }
601
602     public void testFloatArray() {
603         float[] obj1 = new float[2];
604         obj1[0] = 5;
605         obj1[1] = 6;
606         float[] obj2 = new float[2];
607         obj2[0] = 5;
608         obj2[1] = 6;
609         float[] obj3 = new float[3];
610         obj3[0] = 5;
611         obj3[1] = 6;
612         obj3[2] = 7;
613
614         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
615         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
616         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
617         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
618
619         obj1[1] = 7;
620         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
621         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
622
623         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
624         assertTrue(new CompareToBuilder().append((float[]) null, (float[]) null).toComparison() == 0);
625         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
626     }
627
628     public void testBooleanArray() {
629         boolean[] obj1 = new boolean[2];
630         obj1[0] = true;
631         obj1[1] = false;
632         boolean[] obj2 = new boolean[2];
633         obj2[0] = true;
634         obj2[1] = false;
635         boolean[] obj3 = new boolean[3];
636         obj3[0] = true;
637         obj3[1] = false;
638         obj3[2] = true;
639
640         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
641         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
642         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
643         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
644
645         obj1[1] = true;
646         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
647         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
648
649         assertTrue(new CompareToBuilder().append(obj1, null).toComparison() > 0);
650         assertTrue(new CompareToBuilder().append((boolean[]) null, (boolean[]) null).toComparison() == 0);
651         assertTrue(new CompareToBuilder().append(null, obj1).toComparison() < 0);
652     }
653
654     public void testMultiLongArray() {
655         long[][] array1 = new long[2][2];
656         long[][] array2 = new long[2][2];
657         long[][] array3 = new long[2][3];
658         for (int i = 0; i < array1.length; ++i) {
659             for (int j = 0; j < array1[0].length; j++) {
660                 array1[i][j] = (i + 1) * (j + 1);
661                 array2[i][j] = (i + 1) * (j + 1);
662                 array3[i][j] = (i + 1) * (j + 1);
663             }
664         }
665         array3[1][2] = 100;
666         array3[1][2] = 100;
667         
668         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
669         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
670         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
671         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
672         array1[1][1] = 200;
673         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
674         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
675     }
676
677     public void testMultiIntArray() {
678         int[][] array1 = new int[2][2];
679         int[][] array2 = new int[2][2];
680         int[][] array3 = new int[2][3];
681         for (int i = 0; i < array1.length; ++i) {
682             for (int j = 0; j < array1[0].length; j++) {
683                 array1[i][j] = (i + 1) * (j + 1);
684                 array2[i][j] = (i + 1) * (j + 1);
685                 array3[i][j] = (i + 1) * (j + 1);
686             }
687         }
688         array3[1][2] = 100;
689         array3[1][2] = 100;
690         
691         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
692         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
693         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
694         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
695         array1[1][1] = 200;
696         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
697         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
698     }
699
700     public void testMultiShortArray() {
701         short[][] array1 = new short[2][2];
702         short[][] array2 = new short[2][2];
703         short[][] array3 = new short[2][3];
704         for (short i = 0; i < array1.length; ++i) {
705             for (short j = 0; j < array1[0].length; j++) {
706                 array1[i][j] = (short)((i + 1) * (j + 1));
707                 array2[i][j] = (short)((i + 1) * (j + 1));
708                 array3[i][j] = (short)((i + 1) * (j + 1));
709             }
710         }
711         array3[1][2] = 100;
712         array3[1][2] = 100;
713         
714         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
715         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
716         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
717         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
718         array1[1][1] = 200;
719         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
720         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
721     }
722
723     public void testMultiCharArray() {
724         char[][] array1 = new char[2][2];
725         char[][] array2 = new char[2][2];
726         char[][] array3 = new char[2][3];
727         for (short i = 0; i < array1.length; ++i) {
728             for (short j = 0; j < array1[0].length; j++) {
729                 array1[i][j] = (char)((i + 1) * (j + 1));
730                 array2[i][j] = (char)((i + 1) * (j + 1));
731                 array3[i][j] = (char)((i + 1) * (j + 1));
732             }
733         }
734         array3[1][2] = 100;
735         array3[1][2] = 100;
736         
737         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
738         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
739         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
740         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
741         array1[1][1] = 200;
742         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
743         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
744     }
745
746     public void testMultiByteArray() {
747         byte[][] array1 = new byte[2][2];
748         byte[][] array2 = new byte[2][2];
749         byte[][] array3 = new byte[2][3];
750         for (byte i = 0; i < array1.length; ++i) {
751             for (byte j = 0; j < array1[0].length; j++) {
752                 array1[i][j] = (byte)((i + 1) * (j + 1));
753                 array2[i][j] = (byte)((i + 1) * (j + 1));
754                 array3[i][j] = (byte)((i + 1) * (j + 1));
755             }
756         }
757         array3[1][2] = 100;
758         array3[1][2] = 100;
759         
760         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
761         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
762         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
763         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
764         array1[1][1] = 127;
765         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
766         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
767     }
768     
769     public void testMultiFloatArray() {
770         float[][] array1 = new float[2][2];
771         float[][] array2 = new float[2][2];
772         float[][] array3 = new float[2][3];
773         for (int i = 0; i < array1.length; ++i) {
774             for (int j = 0; j < array1[0].length; j++) {
775                 array1[i][j] = ((i + 1) * (j + 1));
776                 array2[i][j] = ((i + 1) * (j + 1));
777                 array3[i][j] = ((i + 1) * (j + 1));
778             }
779         }
780         array3[1][2] = 100;
781         array3[1][2] = 100;
782         
783         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
784         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
785         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
786         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
787         array1[1][1] = 127;
788         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
789         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
790     }
791
792     public void testMultiDoubleArray() {
793         double[][] array1 = new double[2][2];
794         double[][] array2 = new double[2][2];
795         double[][] array3 = new double[2][3];
796         for (int i = 0; i < array1.length; ++i) {
797             for (int j = 0; j < array1[0].length; j++) {
798                 array1[i][j] = ((i + 1) * (j + 1));
799                 array2[i][j] = ((i + 1) * (j + 1));
800                 array3[i][j] = ((i + 1) * (j + 1));
801             }
802         }
803         array3[1][2] = 100;
804         array3[1][2] = 100;
805         
806         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
807         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
808         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
809         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
810         array1[1][1] = 127;
811         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
812         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
813     }
814
815     public void testMultiBooleanArray() {
816         boolean[][] array1 = new boolean[2][2];
817         boolean[][] array2 = new boolean[2][2];
818         boolean[][] array3 = new boolean[2][3];
819         for (int i = 0; i < array1.length; ++i) {
820             for (int j = 0; j < array1[0].length; j++) {
821                 array1[i][j] = ((i == 1) ^ (j == 1));
822                 array2[i][j] = ((i == 1) ^ (j == 1));
823                 array3[i][j] = ((i == 1) ^ (j == 1));
824             }
825         }
826         array3[1][2] = false;
827         array3[1][2] = false;
828         
829         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
830         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
831         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
832         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
833         array1[1][1] = true;
834         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
835         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
836     }
837
838     public void testRaggedArray() {
839         long array1[][] = new long[2][];
840         long array2[][] = new long[2][];
841         long array3[][] = new long[3][];
842         for (int i = 0; i < array1.length; ++i) {
843             array1[i] = new long[2];
844             array2[i] = new long[2];
845             array3[i] = new long[3];
846             for (int j = 0; j < array1[i].length; ++j) {
847                 array1[i][j] = (i + 1) * (j + 1);
848                 array2[i][j] = (i + 1) * (j + 1);
849                 array3[i][j] = (i + 1) * (j + 1);
850             }
851         }
852         array3[1][2] = 100;
853         array3[1][2] = 100;
854         
855         
856         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
857         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
858         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
859         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
860         array1[1][1] = 200;
861         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
862         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
863     }
864
865     public void testMixedArray() {
866         Object JavaDoc array1[] = new Object JavaDoc[2];
867         Object JavaDoc array2[] = new Object JavaDoc[2];
868         Object JavaDoc array3[] = new Object JavaDoc[2];
869         for (int i = 0; i < array1.length; ++i) {
870             array1[i] = new long[2];
871             array2[i] = new long[2];
872             array3[i] = new long[3];
873             for (int j = 0; j < 2; ++j) {
874                 ((long[]) array1[i])[j] = (i + 1) * (j + 1);
875                 ((long[]) array2[i])[j] = (i + 1) * (j + 1);
876                 ((long[]) array3[i])[j] = (i + 1) * (j + 1);
877             }
878         }
879         ((long[]) array3[0])[2] = 1;
880         ((long[]) array3[1])[2] = 1;
881         assertTrue(new CompareToBuilder().append(array1, array1).toComparison() == 0);
882         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() == 0);
883         assertTrue(new CompareToBuilder().append(array1, array3).toComparison() < 0);
884         assertTrue(new CompareToBuilder().append(array3, array1).toComparison() > 0);
885         ((long[]) array1[1])[1] = 200;
886         assertTrue(new CompareToBuilder().append(array1, array2).toComparison() > 0);
887         assertTrue(new CompareToBuilder().append(array2, array1).toComparison() < 0);
888     }
889
890     public void testObjectArrayHiddenByObject() {
891         TestObject[] array1 = new TestObject[2];
892         array1[0] = new TestObject(4);
893         array1[1] = new TestObject(5);
894         TestObject[] array2 = new TestObject[2];
895         array2[0] = new TestObject(4);
896         array2[1] = new TestObject(5);
897         TestObject[] array3 = new TestObject[3];
898         array3[0] = new TestObject(4);
899         array3[1] = new TestObject(5);
900         array3[2] = new TestObject(6);
901         
902         Object JavaDoc obj1 = array1;
903         Object JavaDoc obj2 = array2;
904         Object JavaDoc obj3 = array3;
905         
906         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
907         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
908         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
909         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
910
911         array1[1] = new TestObject(7);
912         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
913         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
914     }
915
916     public void testLongArrayHiddenByObject() {
917         long[] array1 = new long[2];
918         array1[0] = 5L;
919         array1[1] = 6L;
920         long[] array2 = new long[2];
921         array2[0] = 5L;
922         array2[1] = 6L;
923         long[] array3 = new long[3];
924         array3[0] = 5L;
925         array3[1] = 6L;
926         array3[2] = 7L;
927         Object JavaDoc obj1 = array1;
928         Object JavaDoc obj2 = array2;
929         Object JavaDoc obj3 = array3;
930         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
931         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
932         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
933         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
934
935         array1[1] = 7;
936         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
937         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
938     }
939
940     public void testIntArrayHiddenByObject() {
941         int[] array1 = new int[2];
942         array1[0] = 5;
943         array1[1] = 6;
944         int[] array2 = new int[2];
945         array2[0] = 5;
946         array2[1] = 6;
947         int[] array3 = new int[3];
948         array3[0] = 5;
949         array3[1] = 6;
950         array3[2] = 7;
951         Object JavaDoc obj1 = array1;
952         Object JavaDoc obj2 = array2;
953         Object JavaDoc obj3 = array3;
954         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
955         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
956         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
957         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
958
959         array1[1] = 7;
960         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
961         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
962     }
963
964     public void testShortArrayHiddenByObject() {
965         short[] array1 = new short[2];
966         array1[0] = 5;
967         array1[1] = 6;
968         short[] array2 = new short[2];
969         array2[0] = 5;
970         array2[1] = 6;
971         short[] array3 = new short[3];
972         array3[0] = 5;
973         array3[1] = 6;
974         array3[2] = 7;
975         Object JavaDoc obj1 = array1;
976         Object JavaDoc obj2 = array2;
977         Object JavaDoc obj3 = array3;
978         assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
979         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
980         assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
981         assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
982
983         array1[1] = 7;
984         assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
985         assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
986     }
987
988     public void testCharArrayHiddenByObject() {
989         char[] array1 = new char[2];
990         array1[0] = 5;
991         array1[1] = 6;
992         char[] array2 = new char[2];
993         array2[0] = 5;
994         array2[1] = 6;
995         char[] array3 = new char[3];
996         array3[0] = 5;
997         array3[1] = 6;
998         array3[2] = 7;
999         Object JavaDoc obj1 = array1;
1000        Object JavaDoc obj2 = array2;
1001        Object JavaDoc obj3 = array3;
1002        assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
1003        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
1004        assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
1005        assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
1006
1007        array1[1] = 7;
1008        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
1009        assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
1010    }
1011
1012    public void testByteArrayHiddenByObject() {
1013        byte[] array1 = new byte[2];
1014        array1[0] = 5;
1015        array1[1] = 6;
1016        byte[] array2 = new byte[2];
1017        array2[0] = 5;
1018        array2[1] = 6;
1019        byte[] array3 = new byte[3];
1020        array3[0] = 5;
1021        array3[1] = 6;
1022        array3[2] = 7;
1023        Object JavaDoc obj1 = array1;
1024        Object JavaDoc obj2 = array2;
1025        Object JavaDoc obj3 = array3;
1026        assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
1027        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
1028        assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
1029        assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
1030
1031        array1[1] = 7;
1032        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
1033        assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
1034    }
1035
1036    public void testDoubleArrayHiddenByObject() {
1037        double[] array1 = new double[2];
1038        array1[0] = 5;
1039        array1[1] = 6;
1040        double[] array2 = new double[2];
1041        array2[0] = 5;
1042        array2[1] = 6;
1043        double[] array3 = new double[3];
1044        array3[0] = 5;
1045        array3[1] = 6;
1046        array3[2] = 7;
1047        Object JavaDoc obj1 = array1;
1048        Object JavaDoc obj2 = array2;
1049        Object JavaDoc obj3 = array3;
1050        assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
1051        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
1052        assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
1053        assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
1054
1055        array1[1] = 7;
1056        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
1057        assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
1058    }
1059
1060    public void testFloatArrayHiddenByObject() {
1061        float[] array1 = new float[2];
1062        array1[0] = 5;
1063        array1[1] = 6;
1064        float[] array2 = new float[2];
1065        array2[0] = 5;
1066        array2[1] = 6;
1067        float[] array3 = new float[3];
1068        array3[0] = 5;
1069        array3[1] = 6;
1070        array3[2] = 7;
1071        Object JavaDoc obj1 = array1;
1072        Object JavaDoc obj2 = array2;
1073        Object JavaDoc obj3 = array3;
1074        assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
1075        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
1076        assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
1077        assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
1078
1079        array1[1] = 7;
1080        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
1081        assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
1082    }
1083
1084    public void testBooleanArrayHiddenByObject() {
1085        boolean[] array1 = new boolean[2];
1086        array1[0] = true;
1087        array1[1] = false;
1088        boolean[] array2 = new boolean[2];
1089        array2[0] = true;
1090        array2[1] = false;
1091        boolean[] array3 = new boolean[3];
1092        array3[0] = true;
1093        array3[1] = false;
1094        array3[2] = true;
1095        Object JavaDoc obj1 = array1;
1096        Object JavaDoc obj2 = array2;
1097        Object JavaDoc obj3 = array3;
1098        assertTrue(new CompareToBuilder().append(obj1, obj1).toComparison() == 0);
1099        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() == 0);
1100        assertTrue(new CompareToBuilder().append(obj1, obj3).toComparison() < 0);
1101        assertTrue(new CompareToBuilder().append(obj3, obj1).toComparison() > 0);
1102
1103        array1[1] = true;
1104        assertTrue(new CompareToBuilder().append(obj1, obj2).toComparison() > 0);
1105        assertTrue(new CompareToBuilder().append(obj2, obj1).toComparison() < 0);
1106    }
1107  
1108 }
1109
Popular Tags