001: /*
002: * Copyright 2001-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.comparators;
017:
018: import java.util.Comparator;
019: import java.util.LinkedList;
020: import java.util.List;
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: /**
026: * Test the NullComparator.
027: *
028: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
029: *
030: * @author Michael A. Smith
031: */
032: public abstract class TestNullComparator extends AbstractTestComparator {
033:
034: public TestNullComparator(String testName) {
035: super (testName);
036: }
037:
038: public static Test suite() {
039: TestSuite suite = new TestSuite(TestNullComparator.class
040: .getName());
041: suite.addTest(new TestSuite(TestNullComparator1.class));
042: suite.addTest(new TestSuite(TestNullComparator2.class));
043: return suite;
044: }
045:
046: /**
047: * Test the NullComparator with nulls high, using comparable comparator
048: **/
049: public static class TestNullComparator1 extends TestNullComparator {
050:
051: public TestNullComparator1(String testName) {
052: super (testName);
053: }
054:
055: public Comparator makeComparator() {
056: return new NullComparator();
057: }
058:
059: public List getComparableObjectsOrdered() {
060: List list = new LinkedList();
061: list.add(new Integer(1));
062: list.add(new Integer(2));
063: list.add(new Integer(3));
064: list.add(new Integer(4));
065: list.add(new Integer(5));
066: list.add(null);
067: return list;
068: }
069:
070: public String getCanonicalComparatorName(Object object) {
071: return super .getCanonicalComparatorName(object) + "1";
072: }
073: }
074:
075: /**
076: * Test the NullComparator with nulls low using the comparable comparator
077: **/
078: public static class TestNullComparator2 extends TestNullComparator {
079:
080: public TestNullComparator2(String testName) {
081: super (testName);
082: }
083:
084: public Comparator makeComparator() {
085: return new NullComparator(false);
086: }
087:
088: public List getComparableObjectsOrdered() {
089: List list = new LinkedList();
090: list.add(null);
091: list.add(new Integer(1));
092: list.add(new Integer(2));
093: list.add(new Integer(3));
094: list.add(new Integer(4));
095: list.add(new Integer(5));
096: return list;
097: }
098:
099: public String getCanonicalComparatorName(Object object) {
100: return super .getCanonicalComparatorName(object) + "2";
101: }
102: }
103: }
|