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