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