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.DefaultKeyedValueDataset; 52 53 58 public class DefaultKeyedValueDatasetTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(DefaultKeyedValueDatasetTests.class); 67 } 68 69 74 public DefaultKeyedValueDatasetTests(String name) { 75 super(name); 76 } 77 78 81 public void testEquals() { 82 83 DefaultKeyedValueDataset d1 = new DefaultKeyedValueDataset("Test", new Double (45.5)); 84 DefaultKeyedValueDataset d2 = new DefaultKeyedValueDataset("Test", new Double (45.5)); 85 assertTrue(d1.equals(d2)); 86 assertTrue(d2.equals(d1)); 87 88 d1 = new DefaultKeyedValueDataset("Test 1", new Double (45.5)); 89 d2 = new DefaultKeyedValueDataset("Test 2", new Double (45.5)); 90 assertFalse(d1.equals(d2)); 91 92 d1 = new DefaultKeyedValueDataset("Test", new Double (45.5)); 93 d2 = new DefaultKeyedValueDataset("Test", new Double (45.6)); 94 assertFalse(d1.equals(d2)); 95 96 } 97 98 101 public void testCloning() { 102 DefaultKeyedValueDataset d1 = new DefaultKeyedValueDataset("Test", new Double (45.5)); 103 DefaultKeyedValueDataset d2 = null; 104 try { 105 d2 = (DefaultKeyedValueDataset) d1.clone(); 106 } 107 catch (CloneNotSupportedException e) { 108 System.err.println("DefaultKeyedValueDatasetTests.testCloning: failed to clone."); 109 } 110 assertTrue(d1 != d2); 111 assertTrue(d1.getClass() == d2.getClass()); 112 assertTrue(d1.equals(d2)); 113 } 114 115 118 public void testSerialization() { 119 120 DefaultKeyedValueDataset d1 = new DefaultKeyedValueDataset("Test", new Double (25.3)); 121 DefaultKeyedValueDataset d2 = null; 122 123 try { 124 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 125 ObjectOutput out = new ObjectOutputStream (buffer); 126 out.writeObject(d1); 127 out.close(); 128 129 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 130 d2 = (DefaultKeyedValueDataset) in.readObject(); 131 in.close(); 132 } 133 catch (Exception e) { 134 System.out.println(e.toString()); 135 } 136 assertEquals(d1, d2); 137 138 } 139 140 } 141 | Popular Tags |