1 42 43 package org.jfree.data.general.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.general.DefaultKeyedValuesDataset; 57 import org.jfree.data.general.KeyedValuesDataset; 58 59 62 public class DefaultKeyedValuesDatasetTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(DefaultKeyedValuesDatasetTests.class); 71 } 72 73 78 public DefaultKeyedValuesDatasetTests(String name) { 79 super(name); 80 } 81 82 85 public void testCloning() { 86 DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset(); 87 d1.setValue("V1", new Integer (1)); 88 d1.setValue("V2", null); 89 d1.setValue("V3", new Integer (3)); 90 DefaultKeyedValuesDataset d2 = null; 91 try { 92 d2 = (DefaultKeyedValuesDataset) d1.clone(); 93 } 94 catch (CloneNotSupportedException e) { 95 System.err.println("Failed to clone."); 96 } 97 assertTrue(d1 != d2); 98 assertTrue(d1.getClass() == d2.getClass()); 99 assertTrue(d1.equals(d2)); 100 } 101 102 105 public void testSerialization() { 106 107 DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset(); 108 d1.setValue("C1", new Double (234.2)); 109 d1.setValue("C2", null); 110 d1.setValue("C3", new Double (345.9)); 111 d1.setValue("C4", new Double (452.7)); 112 113 KeyedValuesDataset d2 = null; 114 115 try { 116 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 117 ObjectOutput out = new ObjectOutputStream (buffer); 118 out.writeObject(d1); 119 out.close(); 120 121 ObjectInput in = new ObjectInputStream ( 122 new ByteArrayInputStream (buffer.toByteArray()) 123 ); 124 d2 = (KeyedValuesDataset) in.readObject(); 125 in.close(); 126 } 127 catch (Exception e) { 128 System.out.println(e.toString()); 129 } 130 assertEquals(d1, d2); 131 132 } 133 134 } 135 | Popular Tags |