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.TimeSeriesDataItem; 57 58 61 public class TimeSeriesDataItemTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(TimeSeriesDataItemTests.class); 70 } 71 72 77 public TimeSeriesDataItemTests(String name) { 78 super(name); 79 } 80 81 84 protected void setUp() { 85 } 87 88 93 public void testEqualsSelf() { 94 TimeSeriesDataItem item = new TimeSeriesDataItem( 95 new Day(23, 9, 2001), 99.7 96 ); 97 assertTrue(item.equals(item)); 98 } 99 100 103 public void testEquals() { 104 TimeSeriesDataItem item1 = new TimeSeriesDataItem( 105 new Day(23, 9, 2001), 99.7 106 ); 107 TimeSeriesDataItem item2 = new TimeSeriesDataItem( 108 new Day(23, 9, 2001), 99.7 109 ); 110 assertTrue(item1.equals(item2)); 111 assertTrue(item2.equals(item1)); 112 113 item1.setValue(new Integer (5)); 114 assertFalse(item1.equals(item2)); 115 item2.setValue(new Integer (5)); 116 assertTrue(item1.equals(item2)); 117 } 118 119 122 public void testSerialization() { 123 124 TimeSeriesDataItem item1 = new TimeSeriesDataItem( 125 new Day(23, 9, 2001), 99.7 126 ); 127 TimeSeriesDataItem item2 = null; 128 129 try { 130 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 131 ObjectOutput out = new ObjectOutputStream (buffer); 132 out.writeObject(item1); 133 out.close(); 134 135 ObjectInput in = new ObjectInputStream ( 136 new ByteArrayInputStream (buffer.toByteArray()) 137 ); 138 item2 = (TimeSeriesDataItem) in.readObject(); 139 in.close(); 140 } 141 catch (Exception e) { 142 System.out.println(e.toString()); 143 } 144 assertEquals(item1, item2); 145 146 } 147 148 } 149 | Popular Tags |