View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.functor.adapter;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertNull;
23  import static org.junit.Assert.assertTrue;
24  
25  import org.apache.commons.functor.BaseFunctorTest;
26  import org.apache.commons.functor.Predicate;
27  import org.apache.commons.functor.core.Constant;
28  import org.apache.commons.functor.core.RightIdentity;
29  import org.junit.Test;
30  
31  /**
32   * @version $Revision: 1508677 $ $Date: 2013-07-31 00:48:02 +0200 (Mi, 31 Jul 2013) $
33   */
34  public class TestLeftBoundPredicate extends BaseFunctorTest {
35  
36      // Functor Testing Framework
37      // ------------------------------------------------------------------------
38  
39      @Override
40      protected Object makeFunctor() {
41          return new LeftBoundPredicate<Object>(Constant.TRUE,"xyzzy");
42      }
43  
44      // Tests
45      // ------------------------------------------------------------------------
46  
47      @Test
48      public void testTest() throws Exception {
49          Predicate<Boolean> p = new LeftBoundPredicate<Boolean>(
50                  new BinaryFunctionBinaryPredicate<Object, Boolean>(RightIdentity.<Object, Boolean> function()), "foo");
51          assertTrue(p.test(Boolean.TRUE));
52          assertFalse(p.test(Boolean.FALSE));
53      }
54  
55      @Test
56      public void testEquals() throws Exception {
57          Predicate<Boolean> p = new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy");
58          assertEquals(p,p);
59          assertObjectsAreEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy"));
60          assertObjectsAreNotEqual(p,Constant.TRUE);
61          assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.FALSE,"xyzzy"));
62          assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,"foo"));
63          assertObjectsAreNotEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,null));
64          assertObjectsAreEqual(new LeftBoundPredicate<Boolean>(Constant.TRUE,null),new LeftBoundPredicate<Boolean>(Constant.TRUE,null));
65          assertTrue(!p.equals(null));
66      }
67  
68      @Test
69      public void testAdaptNull() throws Exception {
70          assertNull(LeftBoundPredicate.bind(null,"xyzzy"));
71      }
72  
73      @Test
74      public void testAdapt() throws Exception {
75          assertNotNull(LeftBoundPredicate.bind(Constant.FALSE,"xyzzy"));
76          assertNotNull(LeftBoundPredicate.bind(Constant.FALSE,null));
77      }
78  }