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.assertNotNull;
21 import static org.junit.Assert.assertNull;
22
23 import org.apache.commons.functor.BaseFunctorTest;
24 import org.apache.commons.functor.UnaryPredicate;
25 import org.apache.commons.functor.core.Constant;
26 import org.apache.commons.functor.core.RightIdentity;
27 import org.junit.Test;
28
29
30
31
32
33 public class TestLeftBoundPredicate extends BaseFunctorTest {
34
35
36
37
38 protected Object makeFunctor() {
39 return new LeftBoundPredicate<Object>(Constant.TRUE,"xyzzy");
40 }
41
42
43
44
45 @Test
46 public void testTest() throws Exception {
47 UnaryPredicate<Boolean> p = new LeftBoundPredicate<Boolean>(
48 new BinaryFunctionBinaryPredicate<Object, Boolean>(RightIdentity.<Object, Boolean> function()), "foo");
49 assertEquals(true,p.test(Boolean.TRUE));
50 assertEquals(false,p.test(Boolean.FALSE));
51 }
52
53 @Test
54 public void testEquals() throws Exception {
55 UnaryPredicate<Boolean> p = new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy");
56 assertEquals(p,p);
57 assertObjectsAreEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy"));
58 assertObjectsAreNotEqual(p,Constant.TRUE);
59 assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.FALSE,"xyzzy"));
60 assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,"foo"));
61 assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,null));
62 }
63
64 @Test
65 public void testAdaptNull() throws Exception {
66 assertNull(LeftBoundPredicate.bind(null,"xyzzy"));
67 }
68
69 @Test
70 public void testAdapt() throws Exception {
71 assertNotNull(LeftBoundPredicate.bind(Constant.FALSE,"xyzzy"));
72 assertNotNull(LeftBoundPredicate.bind(Constant.FALSE,null));
73 }
74 }