1 41 42 package org.jfree.data.time.junit; 43 44 import java.io.ByteArrayInputStream ; 45 import java.io.ByteArrayOutputStream ; 46 import java.io.ObjectInput ; 47 import java.io.ObjectInputStream ; 48 import java.io.ObjectOutput ; 49 import java.io.ObjectOutputStream ; 50 51 import junit.framework.Test; 52 import junit.framework.TestCase; 53 import junit.framework.TestSuite; 54 55 import org.jfree.data.time.Day; 56 import org.jfree.data.time.TimePeriodValue; 57 58 61 public class TimePeriodValueTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(TimePeriodValueTests.class); 70 } 71 72 77 public TimePeriodValueTests(String name) { 78 super(name); 79 } 80 81 84 protected void setUp() { 85 } 87 88 91 public void testEqualsSelf() { 92 TimePeriodValue tpv = new TimePeriodValue(new Day(), 55.75); 93 assertTrue(tpv.equals(tpv)); 94 } 95 96 99 public void testEquals() { 100 TimePeriodValue tpv1 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); 101 TimePeriodValue tpv2 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); 102 assertTrue(tpv1.equals(tpv2)); 103 assertTrue(tpv2.equals(tpv1)); 104 } 105 106 109 public void testSerialization() { 110 111 TimePeriodValue tpv1 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); 112 TimePeriodValue tpv2 = null; 113 114 try { 115 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 116 ObjectOutput out = new ObjectOutputStream (buffer); 117 out.writeObject(tpv1); 118 out.close(); 119 120 ObjectInput in = new ObjectInputStream ( 121 new ByteArrayInputStream (buffer.toByteArray()) 122 ); 123 tpv2 = (TimePeriodValue) in.readObject(); 124 in.close(); 125 } 126 catch (Exception e) { 127 System.out.println(e.toString()); 128 } 129 assertEquals(tpv1, tpv2); 130 131 } 132 133 } 134 | Popular Tags |