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