1 42 43 package org.jfree.data.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.data.DomainOrder; 57 58 61 public class DomainOrderTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(DomainOrderTests.class); 70 } 71 72 77 public DomainOrderTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 assertEquals(DomainOrder.NONE, DomainOrder.NONE); 86 assertEquals(DomainOrder.ASCENDING, DomainOrder.ASCENDING); 87 assertEquals(DomainOrder.DESCENDING, DomainOrder.DESCENDING); 88 assertFalse(DomainOrder.NONE.equals(DomainOrder.ASCENDING)); 89 assertFalse(DomainOrder.NONE.equals(DomainOrder.DESCENDING)); 90 assertFalse(DomainOrder.NONE.equals(null)); 91 assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.NONE)); 92 assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.DESCENDING)); 93 assertFalse(DomainOrder.ASCENDING.equals(null)); 94 assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.NONE)); 95 assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.ASCENDING)); 96 assertFalse(DomainOrder.DESCENDING.equals(null)); 97 } 98 99 102 public void testHashCode() { 103 DomainOrder d1 = DomainOrder.ASCENDING; 104 DomainOrder d2 = DomainOrder.ASCENDING; 105 assertTrue(d1.equals(d2)); 106 int h1 = d1.hashCode(); 107 int h2 = d2.hashCode(); 108 assertEquals(h1, h2); 109 } 110 111 114 public void testSerialization() { 115 DomainOrder d1 = DomainOrder.ASCENDING; 116 DomainOrder d2 = null; 117 try { 118 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 119 ObjectOutput out = new ObjectOutputStream (buffer); 120 out.writeObject(d1); 121 out.close(); 122 123 ObjectInput in = new ObjectInputStream ( 124 new ByteArrayInputStream (buffer.toByteArray()) 125 ); 126 d2 = (DomainOrder) in.readObject(); 127 in.close(); 128 } 129 catch (Exception e) { 130 System.out.println(e.toString()); 131 } 132 assertEquals(d1, d2); 133 boolean same = d1 == d2; 134 assertEquals(true, same); 135 } 136 137 } 138 | Popular Tags |