1 37 38 package org.jfree.data.junit; 39 40 import java.io.ByteArrayInputStream ; 41 import java.io.ByteArrayOutputStream ; 42 import java.io.ObjectInput ; 43 import java.io.ObjectInputStream ; 44 import java.io.ObjectOutput ; 45 import java.io.ObjectOutputStream ; 46 47 import junit.framework.Test; 48 import junit.framework.TestCase; 49 import junit.framework.TestSuite; 50 51 import org.jfree.data.DefaultKeyedValuesDataset; 52 import org.jfree.data.KeyedValuesDataset; 53 54 59 public class DefaultKeyedValuesDatasetTests extends TestCase { 60 61 66 public static Test suite() { 67 return new TestSuite(DefaultKeyedValuesDatasetTests.class); 68 } 69 70 75 public DefaultKeyedValuesDatasetTests(String name) { 76 super(name); 77 } 78 79 82 public void testCloning() { 83 DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset(); 84 d1.setValue("V1", new Integer (1)); 85 d1.setValue("V2", null); 86 d1.setValue("V3", new Integer (3)); 87 DefaultKeyedValuesDataset d2 = null; 88 try { 89 d2 = (DefaultKeyedValuesDataset) d1.clone(); 90 } 91 catch (CloneNotSupportedException e) { 92 System.err.println("DefaultKeyedValuesDatasetTests.testCloning: failed to clone."); 93 } 94 assertTrue(d1 != d2); 95 assertTrue(d1.getClass() == d2.getClass()); 96 assertTrue(d1.equals(d2)); 97 } 98 99 102 public void testSerialization() { 103 104 DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset(); 105 d1.setValue("C1", new Double (234.2)); 106 d1.setValue("C2", null); 107 d1.setValue("C3", new Double (345.9)); 108 d1.setValue("C4", new Double (452.7)); 109 110 KeyedValuesDataset d2 = null; 111 112 try { 113 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 114 ObjectOutput out = new ObjectOutputStream (buffer); 115 out.writeObject(d1); 116 out.close(); 117 118 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 119 d2 = (KeyedValuesDataset) in.readObject(); 120 in.close(); 121 } 122 catch (Exception e) { 123 System.out.println(e.toString()); 124 } 125 assertEquals(d1, d2); 126 127 } 128 129 } 130 | Popular Tags |