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