1 42 43 package org.jfree.chart.plot.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.chart.ChartRenderingInfo; 57 import org.jfree.chart.plot.PlotRenderingInfo; 58 59 62 public class PlotRenderingInfoTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(PlotRenderingInfoTests.class); 71 } 72 73 78 public PlotRenderingInfoTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo()); 87 PlotRenderingInfo p2 = new PlotRenderingInfo(new ChartRenderingInfo()); 88 assertTrue(p1.equals(p2)); 89 assertTrue(p2.equals(p1)); 90 } 91 92 95 public void testCloning() { 96 PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo()); 97 PlotRenderingInfo p2 = null; 98 try { 99 p2 = (PlotRenderingInfo) p1.clone(); 100 } 101 catch (CloneNotSupportedException e) { 102 e.printStackTrace(); 103 System.err.println("PiePlotTests.testCloning: failed to clone."); 104 } 105 assertTrue(p1 != p2); 106 assertTrue(p1.getClass() == p2.getClass()); 107 assertTrue(p1.equals(p2)); 108 } 109 110 113 public void testSerialization() { 114 115 PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo()); 116 PlotRenderingInfo p2 = null; 117 118 try { 119 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 120 ObjectOutput out = new ObjectOutputStream (buffer); 121 out.writeObject(p1); 122 out.close(); 123 124 ObjectInput in = new ObjectInputStream ( 125 new ByteArrayInputStream (buffer.toByteArray()) 126 ); 127 p2 = (PlotRenderingInfo) in.readObject(); 128 in.close(); 129 } 130 catch (Exception e) { 131 System.out.println(e.toString()); 132 } 133 assertEquals(p1, p2); 134 135 } 136 137 } 138 | Popular Tags |