01: package net.sf.mockcreator.utils;
02:
03: import java.util.ArrayList;
04: import java.util.HashMap;
05: import java.util.HashSet;
06:
07: import net.sf.mockcreator.MockBase;
08: import net.sf.mockcreator.TestCase;
09: import net.sf.mockcreator.utils.CompareByValue;
10:
11: public class RecursiveComparatorTest extends TestCase {
12:
13: public RecursiveComparatorTest(String name) {
14: super (name);
15: }
16:
17: public void testBasic() {
18: assertTrue(CompareByValue.equals(null, null));
19:
20: assertTrue(CompareByValue.equals("Foo", "Fo" + "o"));
21: assertTrue(CompareByValue
22: .equals(new Integer(1), new Integer(1)));
23:
24: assertFalse(CompareByValue.equals(new Long(1), new Integer(1)));
25: assertFalse(CompareByValue.equals(new Long(1), new Long(2)));
26: assertFalse(CompareByValue.equals("Foo", "Bar"));
27: }
28:
29: public void testNulls() {
30: assertTrue(CompareByValue.equals(null, null));
31:
32: assertFalse(CompareByValue.equals(null, "Foo"));
33: assertFalse(CompareByValue.equals("Bar", null));
34:
35: assertFalse(CompareByValue.equals(null, new String[] {}));
36: assertFalse(CompareByValue.equals(null, new ArrayList()));
37: assertFalse(CompareByValue.equals(null, new HashSet()));
38: assertFalse(CompareByValue.equals(null, new HashMap()));
39:
40: assertFalse(CompareByValue.equals(new String[] {}, null));
41: assertFalse(CompareByValue.equals(new ArrayList(), null));
42: assertFalse(CompareByValue.equals(new HashSet(), null));
43: assertFalse(CompareByValue.equals(new HashMap(), null));
44: }
45:
46: public void testMockBase() {
47: MockBase mb1 = new MockBase() {
48: public String __id() {
49: return "ID1";
50: };
51: };
52:
53: MockBase mb2 = new MockBase() {
54: public String __id() {
55: return "ID2";
56: };
57: };
58:
59: MockBase mb3 = new MockBase() {
60: public String __id() {
61: return "ID" + "" + (Math.random() < 1 ? "1" : "5");
62: };
63: };
64:
65: assertTrue(CompareByValue.equals(mb1, mb3));
66: assertTrue(CompareByValue.equals(mb3, mb1));
67:
68: assertFalse(CompareByValue.equals(mb1, mb2));
69: assertFalse(CompareByValue.equals(mb2, mb1));
70:
71: assertFalse(CompareByValue.equals(mb3, mb2));
72: assertFalse(CompareByValue.equals(mb2, mb3));
73: }
74: }
|