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.assertFalse;
21 import static org.junit.Assert.assertNotSame;
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.BinaryPredicate;
27 import org.junit.Test;
28
29
30
31
32
33 public class TestIsNotSame extends BaseFunctorTest {
34
35
36
37
38 protected Object makeFunctor() {
39 return new IsNotSame<Object, Object>();
40 }
41
42
43
44
45 @Test
46 public void testTest() throws Exception {
47 IsNotSame<Object, Object> p = new IsNotSame<Object, Object>();
48 assertFalse("For symmetry, two nulls should be same", p.test(null, null));
49 assertFalse(p.test("foo", "foo"));
50 assertTrue(p.test(null, "foo"));
51 assertTrue(p.test("foo", null));
52 assertTrue(p.test(new Integer(3), new Integer(3)));
53 assertTrue(p.test(null, new Integer(3)));
54 assertTrue(p.test(new Integer(3), null));
55
56 assertTrue(p.test(new Integer(3), new Integer(4)));
57 assertTrue(p.test(new Integer(4), new Integer(3)));
58 assertTrue(p.test("3", new Integer(3)));
59 assertTrue(p.test(new Integer(3), "3"));
60 }
61
62 @Test
63 public void testEquals() throws Exception {
64 BinaryPredicate<Object, Object> f = new IsNotSame<Object, Object>();
65 assertEquals(f, f);
66
67 assertObjectsAreEqual(f, new IsNotSame<Object, Object>());
68 assertObjectsAreEqual(f, IsNotSame.instance());
69 assertObjectsAreNotEqual(f, Constant.truePredicate());
70 }
71
72 @Test
73 public void testConstant() throws Exception {
74 assertEquals(IsNotSame.instance(), IsNotSame.instance());
75 assertNotSame(IsNotSame.instance(), IsNotSame.instance());
76 assertSame(IsNotSame.INSTANCE, IsNotSame.INSTANCE);
77 }
78 }