1 43 44 package org.jfree.chart.junit; 45 46 import java.awt.geom.Rectangle2D ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.chart.ChartRenderingInfo; 59 60 63 public class ChartRenderingInfoTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(ChartRenderingInfoTests.class); 72 } 73 74 79 public ChartRenderingInfoTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 88 ChartRenderingInfo i1 = new ChartRenderingInfo(); 89 ChartRenderingInfo i2 = new ChartRenderingInfo(); 90 assertTrue(i1.equals(i2)); 91 92 i1.setChartArea(new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0)); 93 assertFalse(i1.equals(i2)); 94 i2.setChartArea(new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0)); 95 assertTrue(i1.equals(i2)); 96 97 i1.getPlotInfo().setDataArea(new Rectangle2D.Double (1.0, 1.0, 1.0, 1.0)); 98 assertFalse(i1.equals(i2)); 99 i2.getPlotInfo().setDataArea(new Rectangle2D.Double (1.0, 1.0, 1.0, 1.0)); 100 assertTrue(i1.equals(i2)); 101 } 102 103 106 public void testCloning() { 107 ChartRenderingInfo i1 = new ChartRenderingInfo(); 108 ChartRenderingInfo i2 = null; 109 try { 110 i2 = (ChartRenderingInfo) i1.clone(); 111 } 112 catch (CloneNotSupportedException e) { 113 System.err.println("Failed to clone."); 114 } 115 assertTrue(i1 != i2); 116 assertTrue(i1.getClass() == i2.getClass()); 117 assertTrue(i1.equals(i2)); 118 } 119 120 123 public void testSerialization() { 124 125 ChartRenderingInfo i1 = new ChartRenderingInfo(); 126 i1.setChartArea(new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0)); 127 ChartRenderingInfo i2 = null; 128 try { 129 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 130 ObjectOutput out = new ObjectOutputStream (buffer); 131 out.writeObject(i1); 132 out.close(); 133 134 ObjectInput in = new ObjectInputStream ( 135 new ByteArrayInputStream (buffer.toByteArray()) 136 ); 137 i2 = (ChartRenderingInfo) in.readObject(); 138 in.close(); 139 } 140 catch (Exception e) { 141 e.printStackTrace(); 142 } 143 assertEquals(i1, i2); 144 145 } 146 147 150 public void testSerialization2() { 151 152 ChartRenderingInfo i1 = new ChartRenderingInfo(); 153 i1.getPlotInfo().setDataArea(new Rectangle2D.Double (1.0, 2.0, 3.0, 154 4.0)); 155 ChartRenderingInfo i2 = null; 156 try { 157 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 158 ObjectOutput out = new ObjectOutputStream (buffer); 159 out.writeObject(i1); 160 out.close(); 161 162 ObjectInput in = new ObjectInputStream ( 163 new ByteArrayInputStream (buffer.toByteArray()) 164 ); 165 i2 = (ChartRenderingInfo) in.readObject(); 166 in.close(); 167 } 168 catch (Exception e) { 169 e.printStackTrace(); 170 } 171 assertEquals(i1, i2); 172 assertEquals(i2, i2.getPlotInfo().getOwner()); 173 174 } 175 } 176 | Popular Tags |