01: package com.mockrunner.test.jdbc;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import junit.framework.TestCase;
07:
08: import com.mockrunner.mock.jdbc.MockStruct;
09:
10: public class MockStructTest extends TestCase {
11: private MockStruct prepareTestStruct() {
12: MockStruct struct = new MockStruct("teststruct", new Object[] {
13: new Long(1), "anAttribute2" });
14: struct.addAttribute("myAttribute3");
15: struct.addAttributes(new Object[] { new Integer(4),
16: "anAttribute5" });
17: List list = new ArrayList();
18: list.add("myAttribute6");
19: list.add("myAttribute7");
20: struct.addAttributes(list);
21: return struct;
22: }
23:
24: public void testEquals() throws Exception {
25: MockStruct nullStruct = new MockStruct((String) null);
26: assertFalse(nullStruct.equals(null));
27: assertTrue(nullStruct.equals(nullStruct));
28: MockStruct struct = new MockStruct("test");
29: assertFalse(struct.equals(nullStruct));
30: assertFalse(nullStruct.equals(struct));
31: MockStruct other = new MockStruct("test");
32: assertTrue(struct.equals(other));
33: assertTrue(other.equals(struct));
34: assertEquals(struct.hashCode(), other.hashCode());
35: other = new MockStruct("test") {
36: };
37: assertFalse(other.equals(struct));
38: assertFalse(struct.equals(other));
39: other = new MockStruct("test");
40: other.addAttribute("myAttribute1");
41: assertFalse(other.equals(struct));
42: assertFalse(struct.equals(other));
43: struct.addAttribute("myAttribute1");
44: assertTrue(struct.equals(other));
45: assertTrue(other.equals(struct));
46: assertEquals(struct.hashCode(), other.hashCode());
47: other.addAttributes(new String[] { "1", "2" });
48: assertFalse(other.equals(struct));
49: assertFalse(struct.equals(other));
50: struct.addAttributes(new String[] { "1", "2" });
51: assertTrue(struct.equals(other));
52: assertTrue(other.equals(struct));
53: assertEquals(struct.hashCode(), other.hashCode());
54: }
55:
56: public void testAttributes() throws Exception {
57: doTestAttributes(prepareTestStruct());
58: }
59:
60: public void testToString() throws Exception {
61: MockStruct struct = prepareTestStruct();
62: assertEquals(
63: "Struct data: [1, anAttribute2, myAttribute3, 4, anAttribute5, myAttribute6, myAttribute7]",
64: struct.toString());
65: }
66:
67: public void testClone() throws Exception {
68: MockStruct struct = prepareTestStruct();
69: MockStruct copyStruct = (MockStruct) struct.clone();
70: assertNotSame(struct, copyStruct);
71: doTestAttributes(copyStruct);
72: }
73:
74: public void doTestAttributes(MockStruct struct) throws Exception {
75: assertEquals("teststruct", struct.getSQLTypeName());
76: Object[] attributes = struct.getAttributes();
77: assertEquals(new Long(1), attributes[0]);
78: assertEquals("anAttribute2", attributes[1]);
79: assertEquals("myAttribute3", attributes[2]);
80: assertEquals(new Integer(4), attributes[3]);
81: assertEquals("anAttribute5", attributes[4]);
82: assertEquals("myAttribute6", attributes[5]);
83: assertEquals("myAttribute7", attributes[6]);
84: }
85: }
|