1 42 43 package org.jfree.data.xy.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 import java.util.Date ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.data.xy.OHLCDataItem; 58 59 62 public class OHLCDataItemTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(OHLCDataItemTests.class); 71 } 72 73 78 public OHLCDataItemTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 OHLCDataItem i1 = new OHLCDataItem( 87 new Date (1L), 1.0, 2.0, 3.0, 4.0, 5.0 88 ); 89 OHLCDataItem i2 = new OHLCDataItem( 90 new Date (1L), 1.0, 2.0, 3.0, 4.0, 5.0 91 ); 92 assertTrue(i1.equals(i2)); 93 assertTrue(i2.equals(i1)); 94 } 95 96 99 public void testCloning() { 100 OHLCDataItem i1 = new OHLCDataItem( 101 new Date (1L), 1.0, 2.0, 3.0, 4.0, 5.0 102 ); 103 assertFalse(i1 instanceof Cloneable ); 104 } 105 106 109 public void testSerialization() { 110 OHLCDataItem i1 = new OHLCDataItem( 111 new Date (1L), 1.0, 2.0, 3.0, 4.0, 5.0 112 ); 113 OHLCDataItem i2 = null; 114 115 try { 116 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 117 ObjectOutput out = new ObjectOutputStream (buffer); 118 out.writeObject(i1); 119 out.close(); 120 121 ObjectInput in = new ObjectInputStream ( 122 new ByteArrayInputStream (buffer.toByteArray()) 123 ); 124 i2 = (OHLCDataItem) in.readObject(); 125 in.close(); 126 } 127 catch (Exception e) { 128 e.printStackTrace(); 129 } 130 assertEquals(i1, i2); 131 } 132 133 } 134 | Popular Tags |