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.assertNull;
21 import static org.junit.Assert.assertSame;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
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
34 public class TestRightIdentity extends BaseFunctorTest {
35
36
37
38
39 protected Object makeFunctor() {
40 return RightIdentity.FUNCTION;
41 }
42
43
44
45
46 @Test
47 public void testEvaluate() throws Exception {
48 BinaryFunction<Object, Object, Object> f = RightIdentity.FUNCTION;
49 assertNull(f.evaluate(null,null));
50 assertNull(f.evaluate("xyzzy",null));
51 assertEquals("xyzzy",f.evaluate("abcdefg","xyzzy"));
52 assertEquals("xyzzy",f.evaluate(null,"xyzzy"));
53 assertEquals(new Integer(3),f.evaluate(null,new Integer(3)));
54 Object obj = new Long(12345L);
55 assertSame(obj,f.evaluate(null,obj));
56 assertSame(obj,f.evaluate(obj,obj));
57 }
58
59 @Test
60 public void testTest() throws Exception {
61 BinaryPredicate<Object, Boolean> p = RightIdentity.PREDICATE;
62 assertTrue(p.test(null,Boolean.TRUE));
63 assertTrue(!p.test(null,Boolean.FALSE));
64 try {
65 p.test(null,null);
66 fail("Expected NullPointerException");
67 } catch(NullPointerException e) {
68
69 }
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 }