1 42 43 package org.jfree.chart.junit; 44 45 import java.awt.Graphics2D ; 46 import java.awt.geom.Rectangle2D ; 47 import java.awt.image.BufferedImage ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.ChartFactory; 54 import org.jfree.chart.JFreeChart; 55 import org.jfree.chart.event.ChartChangeEvent; 56 import org.jfree.chart.event.ChartChangeListener; 57 import org.jfree.chart.plot.PiePlot; 58 import org.jfree.data.general.DefaultPieDataset; 59 import org.jfree.data.general.PieDataset; 60 61 64 public class PieChart3DTests extends TestCase { 65 66 67 private JFreeChart pieChart; 68 69 74 public static Test suite() { 75 return new TestSuite(PieChart3DTests.class); 76 } 77 78 83 public PieChart3DTests(String name) { 84 super(name); 85 } 86 87 90 protected void setUp() { 91 DefaultPieDataset dataset = new DefaultPieDataset(); 93 dataset.setValue("Java", new Double (43.2)); 94 dataset.setValue("Visual Basic", new Double (0.0)); 95 dataset.setValue("C/C++", new Double (17.5)); 96 this.pieChart = createPieChart3D(dataset); 97 } 98 99 104 public void testReplaceDatasetOnPieChart() { 105 LocalListener l = new LocalListener(); 106 this.pieChart.addChangeListener(l); 107 PiePlot plot = (PiePlot) this.pieChart.getPlot(); 108 plot.setDataset(null); 109 assertEquals(true, l.flag); 110 assertNull(plot.getDataset()); 111 } 112 113 117 public void testNullValueInDataset() { 118 DefaultPieDataset dataset = new DefaultPieDataset(); 119 dataset.setValue("Section 1", 10.0); 120 dataset.setValue("Section 2", 11.0); 121 dataset.setValue("Section 3", null); 122 JFreeChart chart = createPieChart3D(dataset); 123 boolean success = false; 124 try { 125 BufferedImage image = new BufferedImage ( 126 200 , 100, BufferedImage.TYPE_INT_RGB 127 ); 128 Graphics2D g2 = image.createGraphics(); 129 chart.draw(g2, new Rectangle2D.Double (0, 0, 200, 100), null, null); 130 g2.dispose(); 131 success = true; 132 } 133 catch (Throwable t) { 134 success = false; 135 } 136 assertTrue(success); 137 } 138 139 146 private static JFreeChart createPieChart3D(PieDataset dataset) { 147 148 return ChartFactory.createPieChart3D( 149 "Pie Chart", dataset, true, true, 153 false 154 ); 155 } 156 157 160 static class LocalListener implements ChartChangeListener { 161 162 163 private boolean flag = false; 164 165 170 public void chartChanged(ChartChangeEvent event) { 171 this.flag = true; 172 } 173 174 } 175 176 } 177 | Popular Tags |