KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > comparators > TestNullComparator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.comparators;
17
18 import java.util.Comparator JavaDoc;
19 import java.util.LinkedList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 /**
26  * Test the NullComparator.
27  *
28  * @version $Revision: 1.9 $ $Date: 2004/02/18 01:20:34 $
29  *
30  * @author Michael A. Smith
31  */

32 public abstract class TestNullComparator extends AbstractTestComparator {
33
34     public TestNullComparator(String JavaDoc testName) {
35         super(testName);
36     }
37
38     public static Test suite() {
39         TestSuite suite = new TestSuite(TestNullComparator.class.getName());
40         suite.addTest(new TestSuite(TestNullComparator1.class));
41         suite.addTest(new TestSuite(TestNullComparator2.class));
42         return suite;
43     }
44
45     /**
46      * Test the NullComparator with nulls high, using comparable comparator
47      **/

48     public static class TestNullComparator1 extends TestNullComparator {
49
50     public TestNullComparator1(String JavaDoc testName) {
51         super(testName);
52     }
53
54     public Comparator JavaDoc makeComparator() {
55         return new NullComparator();
56     }
57     
58     public List JavaDoc getComparableObjectsOrdered() {
59         List JavaDoc list = new LinkedList JavaDoc();
60         list.add(new Integer JavaDoc(1));
61         list.add(new Integer JavaDoc(2));
62         list.add(new Integer JavaDoc(3));
63         list.add(new Integer JavaDoc(4));
64         list.add(new Integer JavaDoc(5));
65         list.add(null);
66         return list;
67     }
68
69     public String JavaDoc getCanonicalComparatorName(Object JavaDoc object) {
70         return super.getCanonicalComparatorName(object) + "1";
71     }
72     }
73
74     /**
75      * Test the NullComparator with nulls low using the comparable comparator
76      **/

77     public static class TestNullComparator2 extends TestNullComparator {
78         
79         public TestNullComparator2(String JavaDoc testName) {
80             super(testName);
81         }
82         
83         public Comparator JavaDoc makeComparator() {
84             return new NullComparator(false);
85         }
86         
87         public List JavaDoc getComparableObjectsOrdered() {
88             List JavaDoc list = new LinkedList JavaDoc();
89             list.add(null);
90             list.add(new Integer JavaDoc(1));
91             list.add(new Integer JavaDoc(2));
92             list.add(new Integer JavaDoc(3));
93             list.add(new Integer JavaDoc(4));
94             list.add(new Integer JavaDoc(5));
95             return list;
96         }
97         
98         public String JavaDoc getCanonicalComparatorName(Object JavaDoc object) {
99             return super.getCanonicalComparatorName(object) + "2";
100         }
101     }
102 }
103
Popular Tags