1 42 43 package org.jfree.chart.axis.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.chart.axis.DateTickUnit; 57 58 61 public class DateTickUnitTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(DateTickUnitTests.class); 70 } 71 72 77 public DateTickUnitTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 DateTickUnit t1 = new DateTickUnit(DateTickUnit.DAY, 1); 86 DateTickUnit t2 = new DateTickUnit(DateTickUnit.DAY, 1); 87 assertTrue(t1.equals(t2)); 88 } 89 90 93 public void testHashCode() { 94 DateTickUnit t1 = new DateTickUnit(DateTickUnit.DAY, 1); 95 DateTickUnit t2 = new DateTickUnit(DateTickUnit.DAY, 1); 96 assertTrue(t1.equals(t2)); 97 int h1 = t1.hashCode(); 98 int h2 = t2.hashCode(); 99 assertEquals(h1, h2); 100 } 101 102 105 public void testSerialization() { 106 107 DateTickUnit a1 = new DateTickUnit(DateTickUnit.DAY, 7); 108 DateTickUnit a2 = null; 109 110 try { 111 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 112 ObjectOutput out = new ObjectOutputStream (buffer); 113 out.writeObject(a1); 114 out.close(); 115 116 ObjectInput in = new ObjectInputStream ( 117 new ByteArrayInputStream (buffer.toByteArray()) 118 ); 119 a2 = (DateTickUnit) in.readObject(); 120 in.close(); 121 } 122 catch (Exception e) { 123 System.out.println(e.toString()); 124 } 125 assertEquals(a1, a2); 126 127 } 128 129 } 130 | Popular Tags |