1 | public class DomainOrderTests extends TestCase {↵ | | 1 | public class RangeTypeTests extends TestCase {↵
|
|
2 | /**↵ | | 2 | /**↵
|
3 | * Returns the tests as a test suite.↵ | | 3 | * Returns the tests as a test suite.↵
|
4 | *↵ | | 4 | *↵
|
5 | * @return The test suite.↵ | | 5 | * @return The test suite.↵
|
6 | */↵ | | 6 | */↵
|
7 | public static Test suite() {↵ | | 7 | public static Test suite() {↵
|
8 | return new TestSuite(DomainOrderTests.class);↵ | | 8 | return new TestSuite(RangeTypeTests.class);↵
|
9 | }↵ | | 9 | }↵
|
|
10 | /**↵ | | 10 | /**↵
|
11 | * Constructs a new set of tests.↵ | | 11 | * Constructs a new set of tests.↵
|
12 | *↵ | | 12 | *↵
|
13 | * @param name the name of the tests.↵ | | 13 | * @param name the name of the tests.↵
|
14 | */↵ | | 14 | */↵
|
15 | public DomainOrderTests(String name) {↵ | | 15 | public RangeTypeTests(String name) {↵
|
16 | super(name);↵ | | 16 | super(name);↵
|
17 | }↵ | | 17 | }↵
|
18 | ↵ | | 18 | ↵
|
19 | /**↵ | | 19 | /**↵
|
20 | * Some checks for the equals() method.↵ | | 20 | * Some checks for the equals() method.↵
|
21 | */↵ | | 21 | */↵
|
22 | public void testEquals() {↵ | | 22 | public void testEquals() {↵
|
23 | assertEquals(DomainOrder.NONE, DomainOrder.NONE);↵ | | 23 | assertEquals(↵
|
24 | assertEquals(DomainOrder.ASCENDING, DomainOrder.ASCENDING);↵ | | |
|
25 | assertEquals(DomainOrder.DESCENDING, DomainOrder.DESCENDING↵ | | 24 | RangeType.FULL, RangeType.FULL);↵
|
| | | 25 | assertEquals(RangeType.NEGATIVE, RangeType.NEGATIVE);↵
|
26 | );↵ | | 26 | assertEquals(RangeType.POSITIVE, RangeType.POSITIVE);↵
|
27 | assertFalse(DomainOrder.NONE.equals(DomainOrder.ASCENDING));↵ | | 27 | assertFalse(RangeType.FULL.equals(RangeType.NEGATIVE));↵
|
28 | assertFalse(DomainOrder.NONE.equals(DomainOrder.DESCENDING));↵ | | 28 | assertFalse(RangeType.FULL.equals(RangeType.POSITIVE));↵
|
29 | assertFalse(DomainOrder.NONE.equals(null));↵ | | 29 | assertFalse(RangeType.FULL.equals(null));↵
|
30 | assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.NONE));↵ | | 30 | assertFalse(RangeType.NEGATIVE.equals(RangeType.FULL));↵
|
31 | assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.DESCENDING));↵ | | 31 | assertFalse(RangeType.NEGATIVE.equals(RangeType.POSITIVE));↵
|
32 | assertFalse(DomainOrder.ASCENDING.equals(null));↵ | | 32 | assertFalse(RangeType.NEGATIVE.equals(null));↵
|
33 | assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.NONE));↵ | | 33 | assertFalse(RangeType.POSITIVE.equals(RangeType.NEGATIVE));↵
|
34 | assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.ASCENDING));↵ | | 34 | assertFalse(RangeType.POSITIVE.equals(RangeType.FULL));↵
|
35 | assertFalse(DomainOrder.DESCENDING.equals(null));↵ | | 35 | assertFalse(RangeType.POSITIVE.equals(null));↵
|
36 | }↵ | | 36 | }↵
|
37 | ↵ | | 37 | ↵
|
38 | /**↵ | | 38 | /**↵
|
39 | * Two objects that are equal are required to return the same hashCode. ↵ | | 39 | * Two objects that are equal are required to return the same hashCode. ↵
|
40 | */↵ | | 40 | */↵
|
41 | public void testHashCode() {↵ | | 41 | public void testHashCode() {↵
|
42 | DomainOrder d1 = DomainOrder.ASCENDING;↵ | | 42 | ↵
|
43 | DomainOrder d2 = DomainOrder.ASCENDING↵ | | 43 | RangeType r1 = RangeType.FULL;↵
|
44 | ;↵ | | 44 | RangeType r2 = RangeType.FULL;↵
|
45 | assertTrue(d1.equals(d2));↵ | | 45 | assertTrue(r1.equals(r2));↵
|
46 | int h1 = d1.hashCode();↵ | | 46 | int h1 = r1.hashCode();↵
|
47 | int h2 = d2.hashCode();↵ | | 47 | int h2 = r2.hashCode();↵
|
48 | assertEquals(h1, h2);↵ | | 48 | assertEquals(h1, h2);↵
|
49 | }↵ | | 49 | }↵
|
50 | ↵ | | 50 | ↵
|
51 | /**↵ | | 51 | /**↵
|
52 | * Serialize an instance, restore it, and check for equality.↵ | | 52 | * Serialize an instance, restore it, and check for equality.↵
|
53 | */↵ | | 53 | */↵
|
54 | public void testSerialization() {↵ | | 54 | public void testSerialization() {↵
|
55 | DomainOrder d1 = DomainOrder.ASCENDING;↵ | | 55 | ↵
|
56 | DomainOrder d↵ | | 56 | RangeType r1 = RangeType.FULL;↵
|
57 | 2 = null;↵ | | 57 | RangeType r2 = null;↵
|
58 | try {↵ | | 58 | try {↵
|
59 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵ | | 59 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵
|
60 | ObjectOutput out = new ObjectOutputStream(buffer);↵ | | 60 | ObjectOutput out = new ObjectOutputStream(buffer);↵
|
61 | out.writeObject(d1);↵ | | 61 | out.writeObject(r1);↵
|
62 | out.close();↵ | | 62 | out.close();↵
|
|
63 | ObjectInput in = new ObjectInputStream(↵ | | 63 | ObjectInput in = new ObjectInputStream(↵
|
64 | new ByteArrayInputStream(buffer.toByteArray())↵ | | 64 | new ByteArrayInputStream(buffer.toByteArray())↵
|
65 | );↵ | | 65 | );↵
|
66 | d2 = (DomainOrder) in.readObject();↵ | | 66 | r2 = (RangeType) in.readObject();↵
|
67 | in.close();↵ | | 67 | in.close();↵
|
68 | }↵ | | 68 | }↵
|
69 | catch (Exception e) {↵ | | 69 | catch (Exception e) {↵
|
70 | System.out.println(e.toString());↵ | | 70 | System.out.println(e.toString());↵
|
71 | }↵ | | 71 | }↵
|
72 | assertEquals(d1, d2);↵ | | 72 | assertEquals(r1, r2);↵
|
73 | boolean same = d1 == d2;↵ | | 73 | boolean same = r1 == r2;↵
|
74 | assertEquals(true, same) | | 74 | assertEquals(true, same)
|