1 44 45 package org.jfree.chart.renderer.xy.junit; 46 47 import java.awt.geom.Line2D ; 48 import java.io.ByteArrayInputStream ; 49 import java.io.ByteArrayOutputStream ; 50 import java.io.ObjectInput ; 51 import java.io.ObjectInputStream ; 52 import java.io.ObjectOutput ; 53 import java.io.ObjectOutputStream ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.renderer.xy.StandardXYItemRenderer; 60 import org.jfree.util.UnitType; 61 62 65 public class StandardXYItemRendererTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(StandardXYItemRendererTests.class); 74 } 75 76 81 public StandardXYItemRendererTests(String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 StandardXYItemRenderer r1 = new StandardXYItemRenderer(); 90 StandardXYItemRenderer r2 = new StandardXYItemRenderer(); 91 assertEquals(r1, r2); 92 93 r1.setBaseShapesVisible(true); 94 assertFalse(r1.equals(r2)); 95 r2.setBaseShapesVisible(true); 96 assertTrue(r1.equals(r2)); 97 98 r1.setPlotLines(false); 99 assertFalse(r1.equals(r2)); 100 r2.setPlotLines(false); 101 assertTrue(r1.equals(r2)); 102 103 r1.setPlotImages(true); 104 assertFalse(r1.equals(r2)); 105 r2.setPlotImages(true); 106 assertTrue(r1.equals(r2)); 107 108 r1.setShapesFilled(false); 109 assertFalse(r1.equals(r2)); 110 r2.setShapesFilled(false); 111 assertTrue(r1.equals(r2)); 112 113 r1.setGapThresholdType(UnitType.ABSOLUTE); 114 assertFalse(r1.equals(r2)); 115 r2.setGapThresholdType(UnitType.ABSOLUTE); 116 assertTrue(r1.equals(r2)); 117 118 r1.setGapThreshold(1.23); 119 assertFalse(r1.equals(r2)); 120 r2.setGapThreshold(1.23); 121 assertTrue(r1.equals(r2)); 122 123 r1.setLegendLine(new Line2D.Double (1.0, 2.0, 3.0, 4.0)); 124 assertFalse(r1.equals(r2)); 125 r2.setLegendLine(new Line2D.Double (1.0, 2.0, 3.0, 4.0)); 126 assertTrue(r1.equals(r2)); 127 } 128 129 132 public void testHashcode() { 133 StandardXYItemRenderer r1 = new StandardXYItemRenderer(); 134 StandardXYItemRenderer r2 = new StandardXYItemRenderer(); 135 assertTrue(r1.equals(r2)); 136 int h1 = r1.hashCode(); 137 int h2 = r2.hashCode(); 138 assertEquals(h1, h2); 139 } 140 141 144 public void testCloning() { 145 StandardXYItemRenderer r1 = new StandardXYItemRenderer(); 146 StandardXYItemRenderer r2 = null; 147 try { 148 r2 = (StandardXYItemRenderer) r1.clone(); 149 } 150 catch (CloneNotSupportedException e) { 151 System.err.println("Failed to clone."); 152 } 153 assertTrue(r1 != r2); 154 assertTrue(r1.getClass() == r2.getClass()); 155 assertTrue(r1.equals(r2)); 156 } 157 158 161 public void testSerialization() { 162 163 StandardXYItemRenderer r1 = new StandardXYItemRenderer(); 164 StandardXYItemRenderer r2 = null; 165 166 try { 167 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 168 ObjectOutput out = new ObjectOutputStream (buffer); 169 out.writeObject(r1); 170 out.close(); 171 172 ObjectInput in = new ObjectInputStream ( 173 new ByteArrayInputStream (buffer.toByteArray()) 174 ); 175 r2 = (StandardXYItemRenderer) in.readObject(); 176 in.close(); 177 } 178 catch (Exception e) { 179 System.out.println(e.toString()); 180 } 181 assertEquals(r1, r2); 182 183 } 184 185 } 186 | Popular Tags |