Test DualTreeBidiMap with comparator

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131789 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-06-11 23:29:07 +00:00
parent b03a471292
commit 46fd2cb394
4 changed files with 110 additions and 1 deletions

View File

@ -23,7 +23,7 @@ import junit.framework.TestSuite;
* Entry point for tests.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/02/18 01:20:40 $
* @version $Revision: 1.7 $ $Date: 2004/06/11 23:29:07 $
*
* @author Stephen Colebourne
*/
@ -43,6 +43,7 @@ public class TestAll extends TestCase {
suite.addTest(TestDualHashBidiMap.suite());
suite.addTest(TestDualTreeBidiMap.suite());
suite.addTest(TestDualTreeBidiMap2.suite());
suite.addTest(TestTreeBidiMap.suite());
suite.addTest(TestAbstractOrderedBidiMapDecorator.suite());

View File

@ -0,0 +1,108 @@
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.collections.bidimap;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Map;
import java.util.TreeMap;
import junit.framework.Test;
import junit.textui.TestRunner;
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.BulkTest;
import org.apache.commons.collections.SortedBidiMap;
import org.apache.commons.collections.comparators.ComparableComparator;
import org.apache.commons.collections.comparators.ReverseComparator;
/**
* JUnit tests.
*
* @version $Revision: 1.1 $ $Date: 2004/06/11 23:29:07 $
*
* @author Matthew Hawthorne
* @author Stephen Colebourne
*/
public class TestDualTreeBidiMap2 extends AbstractTestSortedBidiMap {
public static void main(String[] args) {
TestRunner.run(suite());
}
public static Test suite() {
return BulkTest.makeSuite(TestDualTreeBidiMap2.class);
}
public TestDualTreeBidiMap2(String testName) {
super(testName);
}
public BidiMap makeEmptyBidiMap() {
return new DualTreeBidiMap(new ReverseComparator(ComparableComparator.getInstance()));
}
public Map makeConfirmedMap() {
return new TreeMap(new ReverseComparator(ComparableComparator.getInstance()));
}
public void testComparator() {
resetEmpty();
SortedBidiMap bidi = (SortedBidiMap) map;
assertNotNull(bidi.comparator());
assertTrue(bidi.comparator() instanceof ReverseComparator);
}
public void testSerializeDeserializeCheckComparator() throws Exception {
SortedBidiMap obj = (SortedBidiMap) makeObject();
if (obj instanceof Serializable && isTestSerialization()) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(obj);
out.close();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
Object dest = in.readObject();
in.close();
SortedBidiMap bidi = (SortedBidiMap) dest;
assertNotNull(obj.comparator());
assertNotNull(bidi.comparator());
assertTrue(bidi.comparator() instanceof ReverseComparator);
}
}
public String getCompatibilityVersion() {
return "3.Test2";
}
/**
* Override to prevent infinite recursion of tests.
*/
public String[] ignoredTests() {
return new String[] {"TestDualTreeBidiMap2.bulkTestInverseMap.bulkTestInverseMap"};
}
// public void testCreate() throws Exception {
// resetEmpty();
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/DualTreeBidiMap.emptyCollection.version3.Test2.obj");
// resetFull();
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/DualTreeBidiMap.fullCollection.version3.Test2.obj");
// }
}