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.core.comparator;
18  
19  import static org.junit.Assert.fail;
20  
21  import org.apache.commons.functor.BaseFunctorTest;
22  import org.apache.commons.functor.BinaryPredicate;
23  import org.junit.Test;
24  
25  /**
26   * @version $Revision: 1171255 $ $Date: 2011-09-15 22:27:39 +0200 (Thu, 15 Sep 2011) $
27   * @author Rodney Waldhoff
28   */
29  public abstract class BaseComparisonPredicateTest extends BaseFunctorTest {
30  
31      // Tests
32      // ------------------------------------------------------------------------
33  
34      @Test
35      public final void testTestNull() throws Exception {
36          @SuppressWarnings("unchecked")
37          BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>)(makeFunctor());
38          try {
39              p.test(new Integer(2),null);
40              fail("Expected NullPointerException");
41          } catch(NullPointerException e) {
42              // expected
43          }
44          try {
45              p.test(null,new Integer(2));
46              fail("Expected NullPointerException");
47          } catch(NullPointerException e) {
48              // expected
49          }
50          try {
51              p.test(null,null);
52              fail("Expected NullPointerException");
53          } catch(NullPointerException e) {
54              // expected
55          }
56      }
57  
58      @Test
59      public final void testTestNonComparable() throws Exception {
60          @SuppressWarnings("unchecked")
61          BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>)(makeFunctor());
62          try {
63              p.test(new Integer(2),new Object());
64              fail("Expected ClassCastException");
65          } catch(ClassCastException e) {
66              // expected
67          }
68          try {
69              p.test(new Object(),new Integer(2));
70              fail("Expected ClassCastException");
71          } catch(ClassCastException e) {
72              // expected
73          }
74          try {
75              p.test(new Object(),new Object());
76              fail("Expected ClassCastException");
77          } catch(ClassCastException e) {
78              // expected
79          }
80      }
81  
82  }