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