001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ------------------
028: * PieChartTests.java
029: * ------------------
030: * (C) Copyright 2002-2007, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: PieChartTests.java,v 1.1.2.2 2007/03/02 11:16:20 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 11-Jun-2002 : Version 1 (DG);
040: * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041: *
042: */
043:
044: package org.jfree.chart.junit;
045:
046: import junit.framework.Test;
047: import junit.framework.TestCase;
048: import junit.framework.TestSuite;
049:
050: import org.jfree.chart.ChartFactory;
051: import org.jfree.chart.JFreeChart;
052: import org.jfree.chart.event.ChartChangeEvent;
053: import org.jfree.chart.event.ChartChangeListener;
054: import org.jfree.chart.plot.PiePlot;
055: import org.jfree.data.general.DefaultPieDataset;
056:
057: /**
058: * Tests for a pie chart.
059: *
060: */
061: public class PieChartTests extends TestCase {
062:
063: /** A chart. */
064: private JFreeChart pieChart;
065:
066: /**
067: * Returns the tests as a test suite.
068: *
069: * @return The test suite.
070: */
071: public static Test suite() {
072: return new TestSuite(PieChartTests.class);
073: }
074:
075: /**
076: * Constructs a new set of tests.
077: *
078: * @param name the name of the tests.
079: */
080: public PieChartTests(String name) {
081: super (name);
082: }
083:
084: /**
085: * Common test setup.
086: */
087: protected void setUp() {
088:
089: this .pieChart = createPieChart();
090:
091: }
092:
093: /**
094: * Using a regular pie chart, we replace the dataset with null. Expect to
095: * receive notification of a chart change event, and (of course) the
096: * dataset should be null.
097: */
098: public void testReplaceDatasetOnPieChart() {
099: 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: * Creates a pie chart.
109: *
110: * @return The pie chart.
111: */
112: private static JFreeChart createPieChart() {
113: // create a dataset...
114: DefaultPieDataset data = new DefaultPieDataset();
115: data.setValue("Java", new Double(43.2));
116: data.setValue("Visual Basic", new Double(0.0));
117: data.setValue("C/C++", new Double(17.5));
118:
119: // create the chart...
120: return ChartFactory.createPieChart("Pie Chart", // chart title
121: data, // data
122: true, // include legend
123: true, false);
124: }
125:
126: /**
127: * A chart change listener.
128: *
129: */
130: static class LocalListener implements ChartChangeListener {
131:
132: /** A flag. */
133: private boolean flag = false;
134:
135: /**
136: * Event handler.
137: *
138: * @param event the event.
139: */
140: public void chartChanged(ChartChangeEvent event) {
141: this .flag = true;
142: }
143:
144: }
145:
146: }
|