KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > diff > DifferenceTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util.diff;
5
6 import com.tc.exception.ImplementMe;
7 import com.tc.test.TCTestCase;
8
9 /**
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 JavaDoc a() {
21       throw new ImplementMe();
22     }
23
24     public Object JavaDoc b() {
25       throw new ImplementMe();
26     }
27
28     public String JavaDoc toString() {
29       throw new ImplementMe();
30     }
31   }
32
33   public void testConstruction() throws Exception JavaDoc {
34     try {
35       new TestDifference(null);
36       fail("Didn't get NPE on no context");
37     } catch (NullPointerException JavaDoc npe) {
38       // ok
39
}
40   }
41   
42   public void testWhere() throws Exception JavaDoc {
43     DifferenceContext context = DifferenceContext.createInitial().sub("a").sub("b");
44     Difference test = new TestDifference(context);
45     
46     assertSame(context, test.where());
47   }
48   
49   public void testEquals() throws Exception JavaDoc {
50     DifferenceContext contextA = DifferenceContext.createInitial().sub("a");
51     DifferenceContext contextB = DifferenceContext.createInitial().sub("b");
52     
53     Difference a = new TestDifference(contextA);
54     Difference b = new TestDifference(contextB);
55     Difference c = new TestDifference(contextA);
56     
57     assertEquals(a, c);
58     assertEquals(c, a);
59     
60     assertFalse(a.equals(b));
61     assertFalse(b.equals(a));
62     assertFalse(c.equals(b));
63     assertFalse(b.equals(c));
64   }
65
66 }
Popular Tags