1 42 43 package org.jfree.chart.plot.junit; 44 45 import java.awt.BasicStroke ; 46 import java.awt.Color ; 47 import java.awt.Font ; 48 import java.awt.Stroke ; 49 import java.awt.geom.Rectangle2D ; 50 import java.io.ByteArrayInputStream ; 51 import java.io.ByteArrayOutputStream ; 52 import java.io.ObjectInput ; 53 import java.io.ObjectInputStream ; 54 import java.io.ObjectOutput ; 55 import java.io.ObjectOutputStream ; 56 57 import junit.framework.Test; 58 import junit.framework.TestCase; 59 import junit.framework.TestSuite; 60 61 import org.jfree.chart.labels.StandardPieItemLabelGenerator; 62 import org.jfree.chart.plot.PiePlot; 63 import org.jfree.chart.urls.StandardPieURLGenerator; 64 import org.jfree.util.Rotation; 65 66 69 public class PiePlotTests extends TestCase { 70 71 76 public static Test suite() { 77 return new TestSuite(PiePlotTests.class); 78 } 79 80 85 public PiePlotTests(String name) { 86 super(name); 87 } 88 89 92 public void testEquals() { 93 94 PiePlot plot1 = new PiePlot(); 95 PiePlot plot2 = new PiePlot(); 96 assertTrue(plot1.equals(plot2)); 97 assertTrue(plot2.equals(plot1)); 98 99 plot1.setPieIndex(99); 101 assertFalse(plot1.equals(plot2)); 102 plot2.setPieIndex(99); 103 assertTrue(plot1.equals(plot2)); 104 105 plot1.setInteriorGap(0.15); 107 assertFalse(plot1.equals(plot2)); 108 plot2.setInteriorGap(0.15); 109 assertTrue(plot1.equals(plot2)); 110 111 plot1.setCircular(!plot1.isCircular()); 113 assertFalse(plot1.equals(plot2)); 114 plot2.setCircular(false); 115 assertTrue(plot1.equals(plot2)); 116 117 plot1.setStartAngle(Math.PI); 119 assertFalse(plot1.equals(plot2)); 120 plot2.setStartAngle(Math.PI); 121 assertTrue(plot1.equals(plot2)); 122 123 plot1.setDirection(Rotation.ANTICLOCKWISE); 125 assertFalse(plot1.equals(plot2)); 126 plot2.setDirection(Rotation.ANTICLOCKWISE); 127 assertTrue(plot1.equals(plot2)); 128 129 plot1.setIgnoreZeroValues(true); 131 assertFalse(plot1.equals(plot2)); 132 plot2.setIgnoreZeroValues(true); 133 assertTrue(plot1.equals(plot2)); 134 135 plot1.setIgnoreNullValues(true); 137 assertFalse(plot1.equals(plot2)); 138 plot2.setIgnoreNullValues(true); 139 assertTrue(plot1.equals(plot2)); 140 141 plot1.setSectionPaint(Color.red); 143 assertFalse(plot1.equals(plot2)); 144 plot2.setSectionPaint(Color.red); 145 assertTrue(plot1.equals(plot2)); 146 147 plot1.setSectionPaint(2, Color.red); 149 assertFalse(plot1.equals(plot2)); 150 plot2.setSectionPaint(2, Color.red); 151 assertTrue(plot1.equals(plot2)); 152 153 plot1.setBaseSectionPaint(Color.red); 155 assertFalse(plot1.equals(plot2)); 156 plot2.setBaseSectionPaint(Color.red); 157 assertTrue(plot1.equals(plot2)); 158 159 plot1.setSectionOutlinePaint(Color.red); 161 assertFalse(plot1.equals(plot2)); 162 plot2.setSectionOutlinePaint(Color.red); 163 assertTrue(plot1.equals(plot2)); 164 165 plot1.setSectionOutlinePaint(2, Color.red); 167 assertFalse(plot1.equals(plot2)); 168 plot2.setSectionOutlinePaint(2, Color.red); 169 assertTrue(plot1.equals(plot2)); 170 171 plot1.setBaseSectionOutlinePaint(Color.red); 173 assertFalse(plot1.equals(plot2)); 174 plot2.setBaseSectionOutlinePaint(Color.red); 175 assertTrue(plot1.equals(plot2)); 176 177 plot1.setSectionOutlineStroke(new BasicStroke (1.0f)); 179 assertFalse(plot1.equals(plot2)); 180 plot2.setSectionOutlineStroke(new BasicStroke (1.0f)); 181 assertTrue(plot1.equals(plot2)); 182 183 plot1.setSectionOutlineStroke(2, new BasicStroke (1.0f)); 185 assertFalse(plot1.equals(plot2)); 186 plot2.setSectionOutlineStroke(2, new BasicStroke (1.0f)); 187 assertTrue(plot1.equals(plot2)); 188 189 plot1.setBaseSectionOutlineStroke(new BasicStroke (1.0f)); 191 assertFalse(plot1.equals(plot2)); 192 plot2.setBaseSectionOutlineStroke(new BasicStroke (1.0f)); 193 assertTrue(plot1.equals(plot2)); 194 195 plot1.setShadowPaint(Color.red); 197 assertFalse(plot1.equals(plot2)); 198 plot2.setShadowPaint(Color.red); 199 assertTrue(plot1.equals(plot2)); 200 201 plot1.setShadowXOffset(4.4); 203 assertFalse(plot1.equals(plot2)); 204 plot2.setShadowXOffset(4.4); 205 assertTrue(plot1.equals(plot2)); 206 207 plot1.setShadowYOffset(4.4); 209 assertFalse(plot1.equals(plot2)); 210 plot2.setShadowYOffset(4.4); 211 assertTrue(plot1.equals(plot2)); 212 213 plot1.setLabelFont(new Font ("Serif", Font.PLAIN, 18)); 215 assertFalse(plot1.equals(plot2)); 216 plot2.setLabelFont(new Font ("Serif", Font.PLAIN, 18)); 217 assertTrue(plot1.equals(plot2)); 218 219 plot1.setLabelPaint(Color.red); 221 assertFalse(plot1.equals(plot2)); 222 plot2.setLabelPaint(Color.red); 223 assertTrue(plot1.equals(plot2)); 224 225 plot1.setLabelBackgroundPaint(Color.red); 227 assertFalse(plot1.equals(plot2)); 228 plot2.setLabelBackgroundPaint(Color.red); 229 assertTrue(plot1.equals(plot2)); 230 231 plot1.setLabelOutlinePaint(Color.red); 233 assertFalse(plot1.equals(plot2)); 234 plot2.setLabelOutlinePaint(Color.red); 235 assertTrue(plot1.equals(plot2)); 236 237 Stroke s = new BasicStroke (1.1f); 239 plot1.setLabelOutlineStroke(s); 240 assertFalse(plot1.equals(plot2)); 241 plot2.setLabelOutlineStroke(s); 242 assertTrue(plot1.equals(plot2)); 243 244 plot1.setLabelShadowPaint(Color.red); 246 assertFalse(plot1.equals(plot2)); 247 plot2.setLabelShadowPaint(Color.red); 248 assertTrue(plot1.equals(plot2)); 249 250 plot1.setExplodePercent(3, 0.33); 252 assertFalse(plot1.equals(plot2)); 253 plot2.setExplodePercent(3, 0.33); 254 assertTrue(plot1.equals(plot2)); 255 256 plot1.setLabelGenerator(new StandardPieItemLabelGenerator("{2}{1}{0}")); 258 assertFalse(plot1.equals(plot2)); 259 plot2.setLabelGenerator(new StandardPieItemLabelGenerator("{2}{1}{0}")); 260 assertTrue(plot1.equals(plot2)); 261 262 Font f = new Font ("SansSerif", Font.PLAIN, 20); 264 plot1.setLabelFont(f); 265 assertFalse(plot1.equals(plot2)); 266 plot2.setLabelFont(f); 267 assertTrue(plot1.equals(plot2)); 268 269 plot1.setLabelPaint(Color.blue); 271 assertFalse(plot1.equals(plot2)); 272 plot2.setLabelPaint(Color.blue); 273 assertTrue(plot1.equals(plot2)); 274 275 plot1.setMaximumLabelWidth(0.33); 277 assertFalse(plot1.equals(plot2)); 278 plot2.setMaximumLabelWidth(0.33); 279 assertTrue(plot1.equals(plot2)); 280 281 plot1.setLabelGap(0.11); 283 assertFalse(plot1.equals(plot2)); 284 plot2.setLabelGap(0.11); 285 assertTrue(plot1.equals(plot2)); 286 287 plot1.setLabelLinksVisible(false); 289 assertFalse(plot1.equals(plot2)); 290 plot2.setLabelLinksVisible(false); 291 assertTrue(plot1.equals(plot2)); 292 293 plot1.setLabelLinkMargin(0.11); 295 assertFalse(plot1.equals(plot2)); 296 plot2.setLabelLinkMargin(0.11); 297 assertTrue(plot1.equals(plot2)); 298 299 plot1.setLabelLinkPaint(Color.red); 301 assertFalse(plot1.equals(plot2)); 302 plot2.setLabelLinkPaint(Color.red); 303 assertTrue(plot1.equals(plot2)); 304 305 plot1.setLabelLinkStroke(new BasicStroke (1.0f)); 307 assertFalse(plot1.equals(plot2)); 308 plot2.setLabelLinkStroke(new BasicStroke (1.0f)); 309 assertTrue(plot1.equals(plot2)); 310 311 plot1.setToolTipGenerator( 313 new StandardPieItemLabelGenerator("{2}{1}{0}") 314 ); 315 assertFalse(plot1.equals(plot2)); 316 plot2.setToolTipGenerator( 317 new StandardPieItemLabelGenerator("{2}{1}{0}") 318 ); 319 assertTrue(plot1.equals(plot2)); 320 321 plot1.setURLGenerator(new StandardPieURLGenerator("xx")); 323 assertFalse(plot1.equals(plot2)); 324 plot2.setURLGenerator(new StandardPieURLGenerator("xx")); 325 assertTrue(plot1.equals(plot2)); 326 327 plot1.setMinimumArcAngleToDraw(1.0); 329 assertFalse(plot1.equals(plot2)); 330 plot2.setMinimumArcAngleToDraw(1.0); 331 assertTrue(plot1.equals(plot2)); 332 333 plot1.setLegendItemShape(new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0)); 335 assertFalse(plot1.equals(plot2)); 336 plot2.setLegendItemShape(new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0)); 337 assertTrue(plot1.equals(plot2)); 338 339 } 340 341 344 public void testCloning() { 345 PiePlot p1 = new PiePlot(); 346 PiePlot p2 = null; 347 try { 348 p2 = (PiePlot) p1.clone(); 349 } 350 catch (CloneNotSupportedException e) { 351 e.printStackTrace(); 352 System.err.println("Failed to clone."); 353 } 354 assertTrue(p1 != p2); 355 assertTrue(p1.getClass() == p2.getClass()); 356 assertTrue(p1.equals(p2)); 357 } 358 359 362 public void testSerialization() { 363 364 PiePlot p1 = new PiePlot(null); 365 PiePlot p2 = null; 366 367 try { 368 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 369 ObjectOutput out = new ObjectOutputStream (buffer); 370 out.writeObject(p1); 371 out.close(); 372 373 ObjectInput in = new ObjectInputStream ( 374 new ByteArrayInputStream (buffer.toByteArray()) 375 ); 376 p2 = (PiePlot) in.readObject(); 377 in.close(); 378 } 379 catch (Exception e) { 380 e.printStackTrace(); 381 } 382 assertEquals(p1, p2); 383 384 } 385 386 } 387 | Popular Tags |