KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > junit > ChartPanelTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * --------------------
28  * ChartPanelTests.java
29  * --------------------
30  * (C) Copyright 2004, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: ChartPanelTests.java,v 1.1.2.1 2006/10/03 15:41:30 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 13-Jul-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.junit;
44
45 import java.util.EventListener JavaDoc;
46
47 import javax.swing.event.CaretListener JavaDoc;
48
49 import junit.framework.Test;
50 import junit.framework.TestCase;
51 import junit.framework.TestSuite;
52
53 import org.jfree.chart.ChartMouseEvent;
54 import org.jfree.chart.ChartMouseListener;
55 import org.jfree.chart.ChartPanel;
56 import org.jfree.chart.JFreeChart;
57 import org.jfree.chart.plot.XYPlot;
58
59 /**
60  * Tests for the {@link ChartPanel} class.
61  */

62 public class ChartPanelTests extends TestCase implements ChartMouseListener {
63
64     /**
65      * Returns the tests as a test suite.
66      *
67      * @return The test suite.
68      */

69     public static Test suite() {
70         return new TestSuite(ChartPanelTests.class);
71     }
72
73     /**
74      * Constructs a new set of tests.
75      *
76      * @param name the name of the tests.
77      */

78     public ChartPanelTests(String JavaDoc name) {
79         super(name);
80     }
81
82     /**
83      * Test that the constructor will accept a null chart.
84      */

85     public void testConstructor1() {
86         ChartPanel panel = new ChartPanel(null);
87         assertEquals(null, panel.getChart());
88     }
89     
90     /**
91      * Test that it is possible to set the panel's chart to null.
92      */

93     public void testSetChart() {
94         JFreeChart chart = new JFreeChart(new XYPlot());
95         ChartPanel panel = new ChartPanel(chart);
96         panel.setChart(null);
97         assertEquals(null, panel.getChart());
98     }
99     
100     /**
101      * Check the behaviour of the getListeners() method.
102      */

103     public void testGetListeners() {
104         ChartPanel p = new ChartPanel(null);
105         p.addChartMouseListener(this);
106         EventListener JavaDoc[] listeners = p.getListeners(
107                 (Class JavaDoc) ChartMouseListener.class);
108         assertEquals(1, listeners.length);
109         assertEquals(this, listeners[0]);
110         // try a listener type that isn't registered
111
listeners = p.getListeners((Class JavaDoc) CaretListener JavaDoc.class);
112         assertEquals(0, listeners.length);
113         p.removeChartMouseListener(this);
114         listeners = p.getListeners((Class JavaDoc) ChartMouseListener.class);
115         assertEquals(0, listeners.length);
116     
117         // try a null argument
118
boolean pass = false;
119         try {
120             listeners = p.getListeners((Class JavaDoc) null);
121         }
122         catch (NullPointerException JavaDoc 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 JavaDoc.class);
131         }
132         catch (ClassCastException JavaDoc e) {
133             pass = true;
134         }
135         assertTrue(pass);
136     }
137
138     public void chartMouseClicked(ChartMouseEvent event) {
139         // ignore
140
}
141
142     public void chartMouseMoved(ChartMouseEvent event) {
143         // ignore
144
}
145
146 }
147
Popular Tags