01: package net.sf.mockcreator.utils;
02:
03: import java.util.Collections;
04:
05: import net.sf.mockcreator.TestCase;
06: import net.sf.mockcreator.utils.CompareByValue;
07:
08: public class RecursiveComparatorArraysTest extends TestCase {
09:
10: public RecursiveComparatorArraysTest(String name) {
11: super (name);
12: }
13:
14: public void testBasic() {
15: String foo[] = { "Foo", "Bar" };
16: String bar[] = { "Foo", "" };
17: assertFalse(foo == bar);
18:
19: bar[1] = "Bar";
20: assertTrue(CompareByValue.equals(foo, bar));
21: assertTrue(CompareByValue.equals(bar, foo));
22:
23: bar[1] = "Baz";
24: assertFalse(CompareByValue.equals(foo, bar));
25: assertFalse(CompareByValue.equals(bar, foo));
26: }
27:
28: public void testEmpty() {
29: String foo[] = {};
30: String bar[] = {};
31: assertFalse(foo == bar);
32:
33: assertTrue(CompareByValue.equals(foo, bar));
34: assertTrue(CompareByValue.equals(bar, foo));
35: }
36:
37: public void testMismatchLength() {
38: String foo[] = { "foo", "bar" };
39: String bar[] = { "foo" };
40:
41: assertFalse(CompareByValue.equals(foo, bar));
42: assertFalse(CompareByValue.equals(bar, foo));
43: }
44:
45: public void testMismatchOrder() {
46: String foo[] = { "foo", "bar" };
47: String bar[] = { "bar", "foo" };
48:
49: assertFalse(CompareByValue.equals(foo, bar));
50: assertFalse(CompareByValue.equals(bar, foo));
51: }
52:
53: public void testMismatchedType() {
54: int foo[] = { 1 };
55: long bar[] = { 1 };
56:
57: assertFalse(CompareByValue.equals(foo, bar));
58: assertFalse(CompareByValue.equals(bar, foo));
59:
60: Object[] foo2 = { "Foo" };
61: String[] bar2 = { "Foo" };
62:
63: assertFalse(CompareByValue.equals(foo2, bar2));
64: assertFalse(CompareByValue.equals(bar2, foo2));
65: }
66:
67: public void testNestedSets() {
68: Object foo[] = { Collections.singleton("Foo") };
69: Object bar[] = { Collections.singleton("Foo") };
70: assertFalse(foo[0] == bar[0]);
71:
72: assertTrue(CompareByValue.equals(foo, bar));
73: assertTrue(CompareByValue.equals(bar, foo));
74: }
75:
76: public void testNestedArrays() {
77: int[] s1 = { 1, 2, 3 };
78: int[] s2 = { 1, 2, 3 };
79: Object foo[] = { s1, "Foo" };
80: Object bar[] = { s2, "Foo" };
81:
82: assertTrue(CompareByValue.equals(foo, bar));
83: assertTrue(CompareByValue.equals(bar, foo));
84: }
85:
86: public void testNestedArraysMismatch() {
87: int[] s1 = { 1, 2, 3, 4 };
88: int[] s2 = { 1, 2, 3 };
89: Object foo[] = { s1, "Foo" };
90: Object bar[] = { s2, "Foo" };
91:
92: assertFalse(CompareByValue.equals(foo, bar));
93: assertFalse(CompareByValue.equals(bar, foo));
94: }
95: }
|