1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.functor.core.comparator;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import org.junit.Test;
24
25
26
27
28
29 public class TestComparableComparator {
30
31
32
33
34 @Test
35 public void testCompareIntegers() {
36 assertTrue(ComparableComparator.instance().compare(new Integer(Integer.MIN_VALUE),new Integer(Integer.MIN_VALUE)) == 0);
37 assertTrue(ComparableComparator.instance().compare(new Integer(-1),new Integer(-1)) == 0);
38 assertTrue(ComparableComparator.instance().compare(new Integer(0),new Integer(0)) == 0);
39 assertTrue(ComparableComparator.instance().compare(new Integer(Integer.MAX_VALUE),new Integer(Integer.MAX_VALUE)) == 0);
40 assertTrue(ComparableComparator.instance().compare(new Integer(1),new Integer(1)) == 0);
41 }
42
43 @Test
44 public void testCompareIncomparable() {
45 try {
46 ComparableComparator.instance().compare(new Object(),new Integer(2));
47 fail("Expected ClassCastException");
48 } catch(ClassCastException e) {
49
50 }
51 }
52
53 @Test
54 public void testCompareNull() {
55 try {
56 ComparableComparator.instance().compare(null,new Integer(2));
57 fail("Expected NullPointerException");
58 } catch(NullPointerException e) {
59
60 }
61 }
62
63 @Test
64 public void testEqualsAndHashCode() {
65 assertEquals(new ComparableComparator(),new ComparableComparator());
66 assertEquals(new ComparableComparator().hashCode(),new ComparableComparator().hashCode());
67 assertTrue(!new ComparableComparator().equals(null));
68 }
69 }