1 42 43 package org.jfree.chart.junit; 44 45 import junit.framework.Test; 46 import junit.framework.TestCase; 47 import junit.framework.TestSuite; 48 49 import org.jfree.chart.ChartFactory; 50 import org.jfree.chart.JFreeChart; 51 import org.jfree.chart.event.ChartChangeEvent; 52 import org.jfree.chart.event.ChartChangeListener; 53 import org.jfree.chart.plot.PiePlot; 54 import org.jfree.data.general.DefaultPieDataset; 55 56 60 public class PieChartTests extends TestCase { 61 62 63 private JFreeChart pieChart; 64 65 70 public static Test suite() { 71 return new TestSuite(PieChartTests.class); 72 } 73 74 79 public PieChartTests(String name) { 80 super(name); 81 } 82 83 86 protected void setUp() { 87 88 this.pieChart = createPieChart(); 89 90 } 91 92 97 public void testReplaceDatasetOnPieChart() { 98 99 LocalListener l = new LocalListener(); 100 this.pieChart.addChangeListener(l); 101 PiePlot plot = (PiePlot) this.pieChart.getPlot(); 102 plot.setDataset(null); 103 assertEquals(true, l.flag); 104 assertNull(plot.getDataset()); 105 106 } 107 108 113 private static JFreeChart createPieChart() { 114 DefaultPieDataset data = new DefaultPieDataset(); 116 data.setValue("Java", new Double (43.2)); 117 data.setValue("Visual Basic", new Double (0.0)); 118 data.setValue("C/C++", new Double (17.5)); 119 120 return ChartFactory.createPieChart("Pie Chart", data, true, true, 125 false 126 ); 127 } 128 129 133 static class LocalListener implements ChartChangeListener { 134 135 136 private boolean flag = false; 137 138 143 public void chartChanged(ChartChangeEvent event) { 144 this.flag = true; 145 } 146 147 } 148 149 } 150 | Popular Tags |