01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.util.diff;
05:
06: import com.tc.exception.ImplementMe;
07: import com.tc.test.TCTestCase;
08:
09: /**
10: * Unit test for {@link Difference}.
11: */
12: public class DifferenceTest extends TCTestCase {
13:
14: // This just is to get around the fact that Difference is abstract.
15: private static class TestDifference extends Difference {
16: public TestDifference(DifferenceContext where) {
17: super (where);
18: }
19:
20: public Object a() {
21: throw new ImplementMe();
22: }
23:
24: public Object b() {
25: throw new ImplementMe();
26: }
27:
28: public String toString() {
29: throw new ImplementMe();
30: }
31: }
32:
33: public void testConstruction() throws Exception {
34: try {
35: new TestDifference(null);
36: fail("Didn't get NPE on no context");
37: } catch (NullPointerException npe) {
38: // ok
39: }
40: }
41:
42: public void testWhere() throws Exception {
43: DifferenceContext context = DifferenceContext.createInitial()
44: .sub("a").sub("b");
45: Difference test = new TestDifference(context);
46:
47: assertSame(context, test.where());
48: }
49:
50: public void testEquals() throws Exception {
51: DifferenceContext contextA = DifferenceContext.createInitial()
52: .sub("a");
53: DifferenceContext contextB = DifferenceContext.createInitial()
54: .sub("b");
55:
56: Difference a = new TestDifference(contextA);
57: Difference b = new TestDifference(contextB);
58: Difference c = new TestDifference(contextA);
59:
60: assertEquals(a, c);
61: assertEquals(c, a);
62:
63: assertFalse(a.equals(b));
64: assertFalse(b.equals(a));
65: assertFalse(c.equals(b));
66: assertFalse(b.equals(c));
67: }
68:
69: }
|