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.core.comparator;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertFalse;
21  
22  import java.util.Collections;
23  
24  import org.apache.commons.functor.BaseFunctorTest;
25  import org.apache.commons.functor.Function;
26  import org.junit.Test;
27  
28  /**
29   * @version $Revision: 1541658 $ $Date: 2013-11-13 19:54:05 +0100 (Mi, 13 Nov 2013) $
30   */
31  public class TestMax extends BaseFunctorTest {
32  
33      // Framework
34      // ------------------------------------------------------------------------
35  
36      @Override
37      protected Object makeFunctor() {
38          return Max.instance();
39      }
40  
41      private Integer MIN = Integer.valueOf(Integer.MIN_VALUE);
42      private Integer MINUS_TWO = Integer.valueOf(-2);
43      private Integer ZERO = Integer.valueOf(0);
44      private Integer ONE = Integer.valueOf(1);
45      private Integer MAX = Integer.valueOf(Integer.MAX_VALUE);
46      // Tests
47      // ------------------------------------------------------------------------
48  
49      @Test
50      public void testEvaluate() {
51          Max<Integer> f = Max.instance();
52          assertEquals(ONE,f.evaluate(ONE,ONE));
53          assertEquals(ONE,f.evaluate(ZERO,ONE));
54          assertEquals(ONE,f.evaluate(ONE,ZERO));
55          assertEquals(MAX,f.evaluate(ONE,MAX));
56          assertEquals(MAX,f.evaluate(MIN,MAX));
57          assertEquals(MINUS_TWO,f.evaluate(MIN,MINUS_TWO));
58      }
59  
60      @Test
61      public void testEquals() {
62          Max<Comparable<?>> f = Max.instance();
63          assertObjectsAreEqual(f,f);
64          assertObjectsAreEqual(f,Max.instance());
65          assertObjectsAreEqual(f,new Max<Integer>(ComparableComparator.<Integer>instance()));
66          assertObjectsAreNotEqual(f,new Max<Comparable<?>>(Collections.<Comparable<?>>reverseOrder()));
67          assertFalse(f.equals(null));
68      }
69  
70      @Test
71      public void testFunctionMin() {
72          Function<Integer, Integer> max = Max.instance(ONE);
73          assertEquals(ONE,max.evaluate(ZERO));
74      }
75  }