1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.functor.core;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertSame;
23 import static org.junit.Assert.assertTrue;
24
25 import org.apache.commons.functor.BaseFunctorTest;
26 import org.apache.commons.functor.BinaryFunction;
27 import org.apache.commons.functor.BinaryPredicate;
28 import org.junit.Test;
29
30
31
32
33 public class TestRightIdentity extends BaseFunctorTest {
34
35
36
37
38 @Override
39 protected Object makeFunctor() {
40 return RightIdentity.FUNCTION;
41 }
42
43
44
45
46 @Test
47 public void testJavabeanConstructor() {
48 assertNotNull(new RightIdentity());
49 }
50
51 @Test
52 public void testEvaluate() throws Exception {
53 BinaryFunction<Object, Object, Object> f = RightIdentity.FUNCTION;
54 assertNull(f.evaluate(null,null));
55 assertNull(f.evaluate("xyzzy",null));
56 assertEquals("xyzzy",f.evaluate("abcdefg","xyzzy"));
57 assertEquals("xyzzy",f.evaluate(null,"xyzzy"));
58 assertEquals(Integer.valueOf(3),f.evaluate(null,Integer.valueOf(3)));
59 Object obj = Long.valueOf(12345L);
60 assertSame(obj,f.evaluate(null,obj));
61 assertSame(obj,f.evaluate(obj,obj));
62 }
63
64 @Test(expected=NullPointerException.class)
65 public void testTest() throws Exception {
66 BinaryPredicate<Object, Boolean> p = RightIdentity.PREDICATE;
67 assertTrue(p.test(null,Boolean.TRUE));
68 assertTrue(!p.test(null,Boolean.FALSE));
69 p.test(null,null);
70 }
71
72 @Test
73 public void testEquals() throws Exception {
74 BinaryFunction<Object, Object, Object> f = RightIdentity.FUNCTION;
75 assertEquals(f,f);
76 assertObjectsAreEqual(f,RightIdentity.function());
77 assertObjectsAreNotEqual(f,new Identity<Object>());
78 assertObjectsAreNotEqual(f,LeftIdentity.function());
79 assertObjectsAreNotEqual(f,Constant.TRUE);
80 assertObjectsAreNotEqual(f,Constant.of("abcde"));
81 }
82
83 @Test
84 public void testConstant() throws Exception {
85 assertEquals(RightIdentity.function(),RightIdentity.function());
86 }
87 }