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.collections4.comparators;
18  
19  import java.util.Comparator;
20  import java.util.LinkedList;
21  import java.util.List;
22  
23  /**
24   * Test the NullComparator.
25   */
26  public abstract class AbstractNullComparatorTest extends AbstractComparatorTest<Integer> {
27  
28      /**
29       *  Test the NullComparator with nulls high, using comparable comparator
30       **/
31      public static class TestNullComparator1 extends AbstractNullComparatorTest {
32  
33          @Override
34          public String getCanonicalComparatorName(final Object object) {
35              return super.getCanonicalComparatorName(object) + "1";
36          }
37  
38          @Override
39          public List<Integer> getComparableObjectsOrdered() {
40              final List<Integer> list = new LinkedList<>();
41              list.add(Integer.valueOf(1));
42              list.add(Integer.valueOf(2));
43              list.add(Integer.valueOf(3));
44              list.add(Integer.valueOf(4));
45              list.add(Integer.valueOf(5));
46              list.add(null);
47              return list;
48          }
49  
50          @Override
51          public String getCompatibilityVersion() {
52              return "4";
53          }
54  
55          @Override
56          public Comparator<Integer> makeObject() {
57              return new NullComparator<>();
58          }
59  
60  //        public void testCreate() throws Exception {
61  //            writeExternalFormToDisk((java.io.Serializable) makeObject(), "src/test/resources/data/test/NullComparator.version4.obj1");
62  //        }
63  
64      }
65  
66      /**
67       *  Test the NullComparator with nulls low using the comparable comparator
68       **/
69      public static class TestNullComparator2 extends AbstractNullComparatorTest {
70  
71          @Override
72          public String getCanonicalComparatorName(final Object object) {
73              return super.getCanonicalComparatorName(object) + "2";
74          }
75  
76          @Override
77          public List<Integer> getComparableObjectsOrdered() {
78              final List<Integer> list = new LinkedList<>();
79              list.add(null);
80              list.add(Integer.valueOf(1));
81              list.add(Integer.valueOf(2));
82              list.add(Integer.valueOf(3));
83              list.add(Integer.valueOf(4));
84              list.add(Integer.valueOf(5));
85              return list;
86          }
87  
88          @Override
89          public String getCompatibilityVersion() {
90              return "4";
91          }
92  
93          @Override
94          public Comparator<Integer> makeObject() {
95              return new NullComparator<>(false);
96          }
97  
98  //        public void testCreate() throws Exception {
99  //            writeExternalFormToDisk((java.io.Serializable) makeObject(), "src/test/resources/data/test/NullComparator.version4.obj2");
100 //        }
101 
102     }
103 
104 }