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.DefaultKeyedValues2DDataset; 52 53 58 public class DefaultKeyedValues2DDatasetTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(DefaultKeyedValues2DDatasetTests.class); 67 } 68 69 74 public DefaultKeyedValues2DDatasetTests(String name) { 75 super(name); 76 } 77 78 81 public void testCloning() { 82 DefaultKeyedValues2DDataset d1 = new DefaultKeyedValues2DDataset(); 83 d1.setValue(new Integer (1), "V1", "C1"); 84 d1.setValue(null, "V2", "C1"); 85 d1.setValue(new Integer (3), "V3", "C2"); 86 DefaultKeyedValues2DDataset d2 = null; 87 try { 88 d2 = (DefaultKeyedValues2DDataset) d1.clone(); 89 } 90 catch (CloneNotSupportedException e) { 91 System.err.println("DefaultKeyedValues2DDatasetTests.testCloning: failed to clone."); 92 } 93 assertTrue(d1 != d2); 94 assertTrue(d1.getClass() == d2.getClass()); 95 assertTrue(d1.equals(d2)); 96 } 97 98 101 public void testSerialization() { 102 103 DefaultKeyedValues2DDataset d1 = new DefaultKeyedValues2DDataset(); 104 d1.addValue(new Double (234.2), "Row1", "Col1"); 105 d1.addValue(null, "Row1", "Col2"); 106 d1.addValue(new Double (345.9), "Row2", "Col1"); 107 d1.addValue(new Double (452.7), "Row2", "Col2"); 108 109 DefaultKeyedValues2DDataset d2 = null; 110 111 try { 112 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 113 ObjectOutput out = new ObjectOutputStream (buffer); 114 out.writeObject(d1); 115 out.close(); 116 117 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 118 d2 = (DefaultKeyedValues2DDataset) in.readObject(); 119 in.close(); 120 } 121 catch (Exception e) { 122 System.out.println(e.toString()); 123 } 124 assertEquals(d1, d2); 125 126 } 127 128 } 129 | Popular Tags |