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.UnaryFunction;
25 import org.apache.commons.functor.core.Constant;
26 import org.junit.Test;
27
28
29
30
31
32 public class TestFunctionUnaryFunction extends BaseFunctorTest {
33
34
35
36
37 protected Object makeFunctor() {
38 return new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
39 }
40
41
42
43
44 @Test
45 public void testEvaluate() throws Exception {
46 UnaryFunction<Object, Object> f = new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
47 assertEquals("xyzzy",f.evaluate(null));
48 assertEquals("xyzzy",f.evaluate("abc"));
49 }
50
51 @Test
52 public void testEquals() throws Exception {
53 UnaryFunction<Object, Object> f = new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
54 assertEquals(f,f);
55 assertObjectsAreEqual(f,new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy")));
56 assertObjectsAreNotEqual(f,Constant.of("x"));
57 assertObjectsAreNotEqual(f,new FunctionUnaryFunction<Object, Object>(Constant.of(null)));
58 assertObjectsAreNotEqual(f,Constant.of(null));
59 }
60
61 @Test
62 public void testAdaptNull() throws Exception {
63 assertNull(FunctionUnaryFunction.adapt(null));
64 }
65
66 @Test
67 public void testAdapt() throws Exception {
68 assertNotNull(FunctionUnaryFunction.adapt(Constant.of("xyzzy")));
69 }
70 }