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.DefaultPieDataset; 52 53 58 public class PieDatasetTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(PieDatasetTests.class); 67 } 68 69 74 public PieDatasetTests(String name) { 75 super(name); 76 } 77 78 81 public void testCloning() { 82 DefaultPieDataset d1 = new DefaultPieDataset(); 83 d1.setValue("V1", new Integer (1)); 84 d1.setValue("V2", null); 85 d1.setValue("V3", new Integer (3)); 86 DefaultPieDataset d2 = null; 87 try { 88 d2 = (DefaultPieDataset) d1.clone(); 89 } 90 catch (CloneNotSupportedException e) { 91 System.err.println("DefaultPieDatasetTests.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 DefaultPieDataset d1 = new DefaultPieDataset(); 104 d1.setValue("C1", new Double (234.2)); 105 d1.setValue("C2", null); 106 d1.setValue("C3", new Double (345.9)); 107 d1.setValue("C4", new Double (452.7)); 108 109 DefaultPieDataset 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 = (DefaultPieDataset) 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 |