01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.util;
05:
06: import com.tc.test.TCTestCase;
07:
08: /**
09: * Unit test for {@link AbstractIdentifier}.
10: */
11: public class AbstractIdentifierTest extends TCTestCase {
12:
13: public void testNonNullID() {
14: RedFishID r = new RedFishID(100);
15: Assert.assertEquals("RedFish", r.getIdentifierType());
16: Assert.assertEquals(false, r.isNull());
17: Assert.assertEquals(100, r.toLong());
18:
19: // Check equality with self
20: Assert.assertEquals(r, r);
21:
22: // Check equality with "same" but not identical
23: RedFishID s = new RedFishID(100);
24: Assert.assertTrue(r.equals(s));
25:
26: // Check inequality with same value, different class
27: BlueFishID t = new BlueFishID(100);
28: Assert.assertTrue(!r.equals(t));
29: }
30:
31: public void testNullID() {
32: RedFishID r = new RedFishID();
33: Assert.assertEquals("RedFish", r.getIdentifierType());
34: Assert.assertEquals(true, r.isNull());
35: Assert.assertEquals(-1, r.toLong());
36:
37: // Check equality with self
38: Assert.assertEquals(r, r);
39:
40: // Check equality with "same" but not identical
41: RedFishID s = new RedFishID(-1);
42: Assert.assertTrue(r.equals(s));
43:
44: // Check inequality with same value, different class
45: BlueFishID t = new BlueFishID();
46: Assert.assertTrue(!r.equals(t));
47: }
48:
49: private static class RedFishID extends AbstractIdentifier {
50: public RedFishID() {
51: super ();
52: }
53:
54: public RedFishID(long id) {
55: super (id);
56: }
57:
58: public String getIdentifierType() {
59: return "RedFish";
60: }
61: }
62:
63: private static class BlueFishID extends AbstractIdentifier {
64: public BlueFishID() {
65: super ();
66: }
67:
68: public BlueFishID(long id) {
69: super (id);
70: }
71:
72: public String getIdentifierType() {
73: return "BlueFishID";
74: }
75: }
76:
77: }
|