1 42 43 package org.jfree.chart.renderer.category.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.renderer.category.LineAndShapeRenderer; 57 58 61 public class LineAndShapeRendererTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(LineAndShapeRendererTests.class); 70 } 71 72 77 public LineAndShapeRendererTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 86 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 87 LineAndShapeRenderer r2 = new LineAndShapeRenderer(); 88 assertEquals(r1, r2); 89 90 r1.setBaseLinesVisible(!r1.getBaseLinesVisible()); 91 assertFalse(r1.equals(r2)); 92 r2.setBaseLinesVisible(r1.getBaseLinesVisible()); 93 assertTrue(r1.equals(r2)); 94 95 r1.setSeriesLinesVisible(1, true); 96 assertFalse(r1.equals(r2)); 97 r2.setSeriesLinesVisible(1, true); 98 assertTrue(r1.equals(r2)); 99 100 r1.setLinesVisible(false); 101 assertFalse(r1.equals(r2)); 102 r2.setLinesVisible(false); 103 assertTrue(r1.equals(r2)); 104 105 r1.setBaseShapesVisible(!r1.getBaseShapesVisible()); 106 assertFalse(r1.equals(r2)); 107 r2.setBaseShapesVisible(r1.getBaseShapesVisible()); 108 assertTrue(r1.equals(r2)); 109 110 r1.setSeriesShapesVisible(1, true); 111 assertFalse(r1.equals(r2)); 112 r2.setSeriesShapesVisible(1, true); 113 assertTrue(r1.equals(r2)); 114 115 r1.setShapesVisible(false); 116 assertFalse(r1.equals(r2)); 117 r2.setShapesVisible(false); 118 assertTrue(r1.equals(r2)); 119 120 r1.setShapesFilled(false); 121 assertFalse(r1.equals(r2)); 122 r2.setShapesFilled(false); 123 assertTrue(r1.equals(r2)); 124 125 r1.setSeriesShapesFilled(1, true); 126 assertFalse(r1.equals(r2)); 127 r2.setSeriesShapesFilled(1, true); 128 assertTrue(r1.equals(r2)); 129 130 r1.setBaseShapesFilled(false); 131 assertFalse(r1.equals(r2)); 132 r2.setBaseShapesFilled(false); 133 assertTrue(r1.equals(r2)); 134 135 r1.setUseOutlinePaint(true); 136 assertFalse(r1.equals(r2)); 137 r2.setUseOutlinePaint(true); 138 assertTrue(r1.equals(r2)); 139 140 } 141 142 145 public void testHashcode() { 146 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 147 LineAndShapeRenderer r2 = new LineAndShapeRenderer(); 148 assertTrue(r1.equals(r2)); 149 int h1 = r1.hashCode(); 150 int h2 = r2.hashCode(); 151 assertEquals(h1, h2); 152 } 153 154 157 public void testCloning() { 158 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 159 LineAndShapeRenderer r2 = null; 160 try { 161 r2 = (LineAndShapeRenderer) r1.clone(); 162 } 163 catch (CloneNotSupportedException e) { 164 e.printStackTrace(); 165 } 166 assertTrue(r1 != r2); 167 assertTrue(r1.getClass() == r2.getClass()); 168 assertTrue(r1.equals(r2)); 169 170 assertTrue(checkIndependence(r1, r2)); 171 172 } 173 174 182 private boolean checkIndependence(LineAndShapeRenderer r1, 183 LineAndShapeRenderer r2) { 184 185 if (!r1.equals(r2)) { 187 return false; 188 } 189 190 r1.setBaseLinesVisible(!r1.getBaseLinesVisible()); 192 if (r1.equals(r2)) { 193 return false; 194 } 195 r2.setBaseLinesVisible(r1.getBaseLinesVisible()); 196 if (!r1.equals(r2)) { 197 return false; 198 } 199 200 r1.setSeriesLinesVisible(1, true); 201 if (r1.equals(r2)) { 202 return false; 203 } 204 r2.setSeriesLinesVisible(1, true); 205 if (!r1.equals(r2)) { 206 return false; 207 } 208 209 r1.setLinesVisible(false); 210 if (r1.equals(r2)) { 211 return false; 212 } 213 r2.setLinesVisible(false); 214 if (!r1.equals(r2)) { 215 return false; 216 } 217 218 r1.setBaseShapesVisible(!r1.getBaseShapesVisible()); 219 if (r1.equals(r2)) { 220 return false; 221 } 222 r2.setBaseShapesVisible(r1.getBaseShapesVisible()); 223 if (!r1.equals(r2)) { 224 return false; 225 } 226 227 r1.setSeriesShapesVisible(1, true); 228 if (r1.equals(r2)) { 229 return false; 230 } 231 r2.setSeriesShapesVisible(1, true); 232 if (!r1.equals(r2)) { 233 return false; 234 } 235 236 r1.setShapesVisible(false); 237 if (r1.equals(r2)) { 238 return false; 239 } 240 r2.setShapesVisible(false); 241 if (!r1.equals(r2)) { 242 return false; 243 } 244 245 boolean flag = true; 246 Boolean existing = r1.getShapesFilled(); 247 if (existing != null) { 248 flag = !existing.booleanValue(); 249 } 250 r1.setShapesFilled(flag); 251 if (r1.equals(r2)) { 252 return false; 253 } 254 r2.setShapesFilled(flag); 255 if (!r1.equals(r2)) { 256 return false; 257 } 258 259 r1.setShapesFilled(false); 260 r2.setShapesFilled(false); 261 r1.setSeriesShapesFilled(0, false); 262 r2.setSeriesShapesFilled(0, true); 263 if (r1.equals(r2)) { 264 return false; 265 } 266 r2.setSeriesShapesFilled(0, false); 267 if (!r1.equals(r2)) { 268 return false; 269 } 270 271 r1.setBaseShapesFilled(false); 272 r2.setBaseShapesFilled(true); 273 if (r1.equals(r2)) { 274 return false; 275 } 276 r2.setBaseShapesFilled(false); 277 if (!r1.equals(r2)) { 278 return false; 279 } 280 return true; 281 282 } 283 284 287 public void testSerialization() { 288 289 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 290 LineAndShapeRenderer r2 = null; 291 292 try { 293 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 294 ObjectOutput out = new ObjectOutputStream (buffer); 295 out.writeObject(r1); 296 out.close(); 297 298 ObjectInput in = new ObjectInputStream ( 299 new ByteArrayInputStream (buffer.toByteArray()) 300 ); 301 r2 = (LineAndShapeRenderer) in.readObject(); 302 in.close(); 303 } 304 catch (Exception e) { 305 System.out.println(e.toString()); 306 } 307 assertEquals(r1, r2); 308 309 } 310 311 } 312 | Popular Tags |