001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, 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: * ChartPanelTests.java
029: * --------------------
030: * (C) Copyright 2004, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: ChartPanelTests.java,v 1.1.2.1 2006/10/03 15:41:30 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 13-Jul-2004 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.chart.junit;
044:
045: import java.util.EventListener;
046:
047: import javax.swing.event.CaretListener;
048:
049: import junit.framework.Test;
050: import junit.framework.TestCase;
051: import junit.framework.TestSuite;
052:
053: import org.jfree.chart.ChartMouseEvent;
054: import org.jfree.chart.ChartMouseListener;
055: import org.jfree.chart.ChartPanel;
056: import org.jfree.chart.JFreeChart;
057: import org.jfree.chart.plot.XYPlot;
058:
059: /**
060: * Tests for the {@link ChartPanel} class.
061: */
062: public class ChartPanelTests extends TestCase implements
063: ChartMouseListener {
064:
065: /**
066: * Returns the tests as a test suite.
067: *
068: * @return The test suite.
069: */
070: public static Test suite() {
071: return new TestSuite(ChartPanelTests.class);
072: }
073:
074: /**
075: * Constructs a new set of tests.
076: *
077: * @param name the name of the tests.
078: */
079: public ChartPanelTests(String name) {
080: super (name);
081: }
082:
083: /**
084: * Test that the constructor will accept a null chart.
085: */
086: public void testConstructor1() {
087: ChartPanel panel = new ChartPanel(null);
088: assertEquals(null, panel.getChart());
089: }
090:
091: /**
092: * Test that it is possible to set the panel's chart to null.
093: */
094: public void testSetChart() {
095: JFreeChart chart = new JFreeChart(new XYPlot());
096: ChartPanel panel = new ChartPanel(chart);
097: panel.setChart(null);
098: assertEquals(null, panel.getChart());
099: }
100:
101: /**
102: * Check the behaviour of the getListeners() method.
103: */
104: public void testGetListeners() {
105: ChartPanel p = new ChartPanel(null);
106: p.addChartMouseListener(this );
107: EventListener[] listeners = p
108: .getListeners((Class) ChartMouseListener.class);
109: assertEquals(1, listeners.length);
110: assertEquals(this , listeners[0]);
111: // try a listener type that isn't registered
112: listeners = p.getListeners((Class) CaretListener.class);
113: assertEquals(0, listeners.length);
114: p.removeChartMouseListener(this );
115: listeners = p.getListeners((Class) ChartMouseListener.class);
116: assertEquals(0, listeners.length);
117:
118: // try a null argument
119: boolean pass = false;
120: try {
121: listeners = p.getListeners((Class) null);
122: } catch (NullPointerException e) {
123: pass = true;
124: }
125: assertTrue(pass);
126:
127: // try a class that isn't a listener
128: pass = false;
129: try {
130: listeners = p.getListeners(Integer.class);
131: } catch (ClassCastException e) {
132: pass = true;
133: }
134: assertTrue(pass);
135: }
136:
137: public void chartMouseClicked(ChartMouseEvent event) {
138: // ignore
139: }
140:
141: public void chartMouseMoved(ChartMouseEvent event) {
142: // ignore
143: }
144:
145: }
|