1 16 package org.apache.commons.collections.comparators; 17 18 import java.io.ByteArrayInputStream ; 19 import java.io.ByteArrayOutputStream ; 20 import java.io.ObjectInputStream ; 21 import java.io.ObjectOutputStream ; 22 import java.util.Collections ; 23 import java.util.Comparator ; 24 import java.util.LinkedList ; 25 import java.util.List ; 26 27 import junit.framework.Test; 28 import junit.framework.TestSuite; 29 30 37 public class TestReverseComparator extends AbstractTestComparator { 38 39 public TestReverseComparator(String testName) { 40 super(testName); 41 } 42 43 public static Test suite() { 44 return new TestSuite(TestReverseComparator.class); 45 } 46 47 57 public Comparator makeComparator() { 58 return new ReverseComparator(Collections.reverseOrder()); 59 } 60 61 public List getComparableObjectsOrdered() { 62 List list = new LinkedList (); 63 list.add(new Integer (1)); 64 list.add(new Integer (2)); 65 list.add(new Integer (3)); 66 list.add(new Integer (4)); 67 list.add(new Integer (5)); 68 return list; 69 } 70 71 76 public void testSerializeDeserializeThenCompare() throws Exception { 77 Comparator comp = new ReverseComparator(new ComparableComparator()); 78 79 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 80 ObjectOutputStream out = new ObjectOutputStream (buffer); 81 out.writeObject(comp); 82 out.close(); 83 84 ObjectInputStream in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 85 Object dest = in.readObject(); 86 in.close(); 87 assertEquals("obj != deserialize(serialize(obj))",comp,dest); 88 } 89 90 } 91 | Popular Tags |