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.fail;
20
21 import org.apache.commons.functor.BaseFunctorTest;
22 import org.apache.commons.functor.BinaryPredicate;
23 import org.junit.Test;
24
25
26
27
28
29 public abstract class BaseComparisonPredicateTest extends BaseFunctorTest {
30
31
32
33
34 @Test
35 public final void testTestNull() throws Exception {
36 @SuppressWarnings("unchecked")
37 BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>)(makeFunctor());
38 try {
39 p.test(new Integer(2),null);
40 fail("Expected NullPointerException");
41 } catch(NullPointerException e) {
42
43 }
44 try {
45 p.test(null,new Integer(2));
46 fail("Expected NullPointerException");
47 } catch(NullPointerException e) {
48
49 }
50 try {
51 p.test(null,null);
52 fail("Expected NullPointerException");
53 } catch(NullPointerException e) {
54
55 }
56 }
57
58 @Test
59 public final void testTestNonComparable() throws Exception {
60 @SuppressWarnings("unchecked")
61 BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>)(makeFunctor());
62 try {
63 p.test(new Integer(2),new Object());
64 fail("Expected ClassCastException");
65 } catch(ClassCastException e) {
66
67 }
68 try {
69 p.test(new Object(),new Integer(2));
70 fail("Expected ClassCastException");
71 } catch(ClassCastException e) {
72
73 }
74 try {
75 p.test(new Object(),new Object());
76 fail("Expected ClassCastException");
77 } catch(ClassCastException e) {
78
79 }
80 }
81
82 }