1 43 44 package org.jfree.chart.plot.junit; 45 46 import java.awt.BasicStroke ; 47 import java.awt.Color ; 48 import java.awt.Font ; 49 import java.awt.GradientPaint ; 50 import java.awt.Graphics2D ; 51 import java.awt.Rectangle ; 52 import java.awt.geom.Rectangle2D ; 53 import java.awt.image.BufferedImage ; 54 import java.io.ByteArrayInputStream ; 55 import java.io.ByteArrayOutputStream ; 56 import java.io.ObjectInput ; 57 import java.io.ObjectInputStream ; 58 import java.io.ObjectOutput ; 59 import java.io.ObjectOutputStream ; 60 import java.text.DecimalFormat ; 61 62 import junit.framework.Test; 63 import junit.framework.TestCase; 64 import junit.framework.TestSuite; 65 66 import org.jfree.chart.JFreeChart; 67 import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; 68 import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 69 import org.jfree.chart.plot.SpiderWebPlot; 70 import org.jfree.chart.urls.StandardCategoryURLGenerator; 71 import org.jfree.data.category.DefaultCategoryDataset; 72 import org.jfree.util.Rotation; 73 import org.jfree.util.TableOrder; 74 75 78 public class SpiderWebPlotTests extends TestCase { 79 80 85 public static Test suite() { 86 return new TestSuite(SpiderWebPlotTests.class); 87 } 88 89 94 public SpiderWebPlotTests(String name) { 95 super(name); 96 } 97 98 101 public void testEquals() { 102 SpiderWebPlot p1 = new SpiderWebPlot(new DefaultCategoryDataset()); 103 SpiderWebPlot p2 = new SpiderWebPlot(new DefaultCategoryDataset()); 104 assertTrue(p1.equals(p2)); 105 assertTrue(p2.equals(p1)); 106 107 p1.setDataExtractOrder(TableOrder.BY_COLUMN); 109 assertFalse(p1.equals(p2)); 110 p2.setDataExtractOrder(TableOrder.BY_COLUMN); 111 assertTrue(p1.equals(p2)); 112 113 p1.setHeadPercent(0.321); 115 assertFalse(p1.equals(p2)); 116 p2.setHeadPercent(0.321); 117 assertTrue(p1.equals(p2)); 118 119 p1.setInteriorGap(0.123); 121 assertFalse(p1.equals(p2)); 122 p2.setInteriorGap(0.123); 123 assertTrue(p1.equals(p2)); 124 125 p1.setStartAngle(0.456); 127 assertFalse(p1.equals(p2)); 128 p2.setStartAngle(0.456); 129 assertTrue(p1.equals(p2)); 130 131 p1.setDirection(Rotation.ANTICLOCKWISE); 133 assertFalse(p1.equals(p2)); 134 p2.setDirection(Rotation.ANTICLOCKWISE); 135 assertTrue(p1.equals(p2)); 136 137 p1.setMaxValue(123.4); 139 assertFalse(p1.equals(p2)); 140 p2.setMaxValue(123.4); 141 assertTrue(p1.equals(p2)); 142 143 p1.setLegendItemShape(new Rectangle (1, 2, 3, 4)); 145 assertFalse(p1.equals(p2)); 146 p2.setLegendItemShape(new Rectangle (1, 2, 3, 4)); 147 assertTrue(p1.equals(p2)); 148 149 p1.setSeriesPaint(new GradientPaint (1.0f, 2.0f, Color.red, 151 3.0f, 4.0f, Color.white)); 152 assertFalse(p1.equals(p2)); 153 p2.setSeriesPaint(new GradientPaint (1.0f, 2.0f, Color.red, 154 3.0f, 4.0f, Color.white)); 155 assertTrue(p1.equals(p2)); 156 157 p1.setSeriesPaint(1, new GradientPaint (1.0f, 2.0f, Color.yellow, 159 3.0f, 4.0f, Color.white)); 160 assertFalse(p1.equals(p2)); 161 p2.setSeriesPaint(1, new GradientPaint (1.0f, 2.0f, Color.yellow, 162 3.0f, 4.0f, Color.white)); 163 assertTrue(p1.equals(p2)); 164 165 p1.setBaseSeriesPaint(new GradientPaint (1.0f, 2.0f, Color.red, 167 3.0f, 4.0f, Color.black)); 168 assertFalse(p1.equals(p2)); 169 p2.setBaseSeriesPaint(new GradientPaint (1.0f, 2.0f, Color.red, 170 3.0f, 4.0f, Color.black)); 171 assertTrue(p1.equals(p2)); 172 173 p1.setSeriesOutlinePaint(new GradientPaint (1.0f, 2.0f, Color.blue, 175 3.0f, 4.0f, Color.black)); 176 assertFalse(p1.equals(p2)); 177 p2.setSeriesOutlinePaint(new GradientPaint (1.0f, 2.0f, Color.blue, 178 3.0f, 4.0f, Color.black)); 179 assertTrue(p1.equals(p2)); 180 181 p1.setSeriesOutlinePaint(1, new GradientPaint (1.0f, 2.0f, Color.blue, 183 3.0f, 4.0f, Color.green)); 184 assertFalse(p1.equals(p2)); 185 p2.setSeriesOutlinePaint(1, new GradientPaint (1.0f, 2.0f, Color.blue, 186 3.0f, 4.0f, Color.green)); 187 assertTrue(p1.equals(p2)); 188 189 p1.setBaseSeriesOutlinePaint(new GradientPaint (1.0f, 2.0f, Color.cyan, 191 3.0f, 4.0f, Color.green)); 192 assertFalse(p1.equals(p2)); 193 p2.setBaseSeriesOutlinePaint(new GradientPaint (1.0f, 2.0f, Color.cyan, 194 3.0f, 4.0f, Color.green)); 195 assertTrue(p1.equals(p2)); 196 197 BasicStroke s = new BasicStroke (1.23f); 199 p1.setSeriesOutlineStroke(s); 200 assertFalse(p1.equals(p2)); 201 p2.setSeriesOutlineStroke(s); 202 assertTrue(p1.equals(p2)); 203 204 p1.setSeriesOutlineStroke(1, s); 206 assertFalse(p1.equals(p2)); 207 p2.setSeriesOutlineStroke(1, s); 208 assertTrue(p1.equals(p2)); 209 210 p1.setBaseSeriesOutlineStroke(s); 212 assertFalse(p1.equals(p2)); 213 p2.setBaseSeriesOutlineStroke(s); 214 assertTrue(p1.equals(p2)); 215 216 p1.setWebFilled(false); 218 assertFalse(p1.equals(p2)); 219 p2.setWebFilled(false); 220 assertTrue(p1.equals(p2)); 221 222 224 p1.setLabelFont(new Font ("Serif", Font.PLAIN, 9)); 226 assertFalse(p1.equals(p2)); 227 p2.setLabelFont(new Font ("Serif", Font.PLAIN, 9)); 228 assertTrue(p1.equals(p2)); 229 230 p1.setLabelPaint(new GradientPaint (1.0f, 2.0f, Color.red, 232 3.0f, 4.0f, Color.blue)); 233 assertFalse(p1.equals(p2)); 234 p2.setLabelPaint(new GradientPaint (1.0f, 2.0f, Color.red, 235 3.0f, 4.0f, Color.blue)); 236 assertTrue(p1.equals(p2)); 237 238 p1.setLabelGenerator(new StandardCategoryItemLabelGenerator("XYZ: {0}", 240 new DecimalFormat ("0.000"))); 241 assertFalse(p1.equals(p2)); 242 p2.setLabelGenerator(new StandardCategoryItemLabelGenerator("XYZ: {0}", 243 new DecimalFormat ("0.000"))); 244 assertTrue(p1.equals(p2)); 245 246 p1.setToolTipGenerator(new StandardCategoryToolTipGenerator()); 248 assertFalse(p1.equals(p2)); 249 p2.setToolTipGenerator(new StandardCategoryToolTipGenerator()); 250 assertTrue(p1.equals(p2)); 251 252 p1.setURLGenerator(new StandardCategoryURLGenerator()); 254 assertFalse(p1.equals(p2)); 255 p2.setURLGenerator(new StandardCategoryURLGenerator()); 256 assertTrue(p1.equals(p2)); 257 } 258 259 262 public void testCloning() { 263 SpiderWebPlot p1 = new SpiderWebPlot(new DefaultCategoryDataset()); 264 SpiderWebPlot p2 = null; 265 try { 266 p2 = (SpiderWebPlot) p1.clone(); 267 } 268 catch (CloneNotSupportedException e) { 269 e.printStackTrace(); 270 } 271 assertTrue(p1 != p2); 272 assertTrue(p1.getClass() == p2.getClass()); 273 assertTrue(p1.equals(p2)); 274 } 275 276 279 public void testSerialization() { 280 281 SpiderWebPlot p1 = new SpiderWebPlot(new DefaultCategoryDataset()); 282 SpiderWebPlot p2 = null; 283 284 try { 285 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 286 ObjectOutput out = new ObjectOutputStream (buffer); 287 out.writeObject(p1); 288 out.close(); 289 290 ObjectInput in = new ObjectInputStream ( 291 new ByteArrayInputStream (buffer.toByteArray()) 292 ); 293 p2 = (SpiderWebPlot) in.readObject(); 294 in.close(); 295 } 296 catch (Exception e) { 297 e.printStackTrace(); 298 } 299 assertEquals(p1, p2); 300 301 } 302 303 307 public void testDrawWithNullInfo() { 308 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 309 dataset.addValue(35.0, "S1", "C1"); 310 dataset.addValue(45.0, "S1", "C2"); 311 dataset.addValue(55.0, "S1", "C3"); 312 dataset.addValue(15.0, "S1", "C4"); 313 dataset.addValue(25.0, "S1", "C5"); 314 SpiderWebPlot plot = new SpiderWebPlot(dataset); 315 JFreeChart chart = new JFreeChart(plot); 316 boolean success = false; 317 try { 318 BufferedImage image = new BufferedImage (200 , 100, 319 BufferedImage.TYPE_INT_RGB); 320 Graphics2D g2 = image.createGraphics(); 321 chart.draw(g2, new Rectangle2D.Double (0, 0, 200, 100), null, null); 322 g2.dispose(); 323 success = true; 324 } 325 catch (Exception e) { 326 success = false; 327 } 328 assertTrue(success); 329 } 330 331 } 332 | Popular Tags |