01: package com.mockrunner.test.jdbc;
02:
03: import java.util.Arrays;
04:
05: import junit.framework.TestCase;
06:
07: import com.mockrunner.mock.jdbc.MockRowId;
08:
09: public class MockRowIdTest extends TestCase {
10: private MockRowId rowId;
11:
12: protected void setUp() throws Exception {
13: super .setUp();
14: rowId = new MockRowId(new byte[] { 1, 2, 3 });
15: }
16:
17: public void testGetBytes() throws Exception {
18: assertTrue(Arrays.equals(rowId.getBytes(),
19: new byte[] { 1, 2, 3 }));
20: MockRowId emptyRowId = new MockRowId(new byte[0]);
21: assertTrue(Arrays.equals(emptyRowId.getBytes(), new byte[0]));
22: }
23:
24: public void testEquals() throws Exception {
25: assertFalse(rowId.equals(null));
26: assertTrue(rowId.equals(rowId));
27: MockRowId rowId2 = new MockRowId(new byte[] { 1, 2, 3, 4 });
28: assertFalse(rowId.equals(rowId2));
29: assertFalse(rowId2.equals(rowId));
30: rowId2 = new MockRowId(new byte[] { 1, 2, 3 });
31: assertTrue(rowId.equals(rowId2));
32: assertTrue(rowId2.equals(rowId));
33: assertEquals(rowId.hashCode(), rowId2.hashCode());
34: }
35:
36: public void testClone() throws Exception {
37: MockRowId cloneRowId = (MockRowId) rowId.clone();
38: assertTrue(Arrays.equals(rowId.getBytes(), cloneRowId
39: .getBytes()));
40: rowId.getBytes()[0] = 25;
41: assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, cloneRowId
42: .getBytes()));
43: cloneRowId = (MockRowId) new MockRowId(new byte[0]).clone();
44: assertTrue(Arrays.equals(new byte[0], cloneRowId.getBytes()));
45: }
46:
47: public void testToString() throws Exception {
48: MockRowId rowId = new MockRowId(new byte[0]);
49: assertEquals(MockRowId.class.getName() + ": []", rowId
50: .toString());
51: rowId = new MockRowId(new byte[] { 1 });
52: assertEquals(MockRowId.class.getName() + ": [1]", rowId
53: .toString());
54: rowId = new MockRowId(new byte[] { 1, 2, 3 });
55: assertEquals(MockRowId.class.getName() + ": [1, 2, 3]", rowId
56: .toString());
57: }
58: }
|