1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.functor.adapter;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertNull;
23 import static org.junit.Assert.assertTrue;
24
25 import org.apache.commons.functor.BaseFunctorTest;
26 import org.apache.commons.functor.Predicate;
27 import org.apache.commons.functor.core.Constant;
28 import org.apache.commons.functor.core.RightIdentity;
29 import org.junit.Test;
30
31
32
33
34 public class TestLeftBoundPredicate extends BaseFunctorTest {
35
36
37
38
39 @Override
40 protected Object makeFunctor() {
41 return new LeftBoundPredicate<Object>(Constant.TRUE,"xyzzy");
42 }
43
44
45
46
47 @Test
48 public void testTest() throws Exception {
49 Predicate<Boolean> p = new LeftBoundPredicate<Boolean>(
50 new BinaryFunctionBinaryPredicate<Object, Boolean>(RightIdentity.<Object, Boolean> function()), "foo");
51 assertTrue(p.test(Boolean.TRUE));
52 assertFalse(p.test(Boolean.FALSE));
53 }
54
55 @Test
56 public void testEquals() throws Exception {
57 Predicate<Boolean> p = new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy");
58 assertEquals(p,p);
59 assertObjectsAreEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy"));
60 assertObjectsAreNotEqual(p,Constant.TRUE);
61 assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.FALSE,"xyzzy"));
62 assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,"foo"));
63 assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,null));
64 assertObjectsAreEqual(new LeftBoundPredicate<Boolean>(Constant.TRUE,null),new LeftBoundPredicate<Boolean>(Constant.TRUE,null));
65 assertTrue(!p.equals(null));
66 }
67
68 @Test
69 public void testAdaptNull() throws Exception {
70 assertNull(LeftBoundPredicate.bind(null,"xyzzy"));
71 }
72
73 @Test
74 public void testAdapt() throws Exception {
75 assertNotNull(LeftBoundPredicate.bind(Constant.FALSE,"xyzzy"));
76 assertNotNull(LeftBoundPredicate.bind(Constant.FALSE,null));
77 }
78 }