KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > junit > PlotTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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  * PlotTests.java
29  * --------------
30  * (C) Copyright 2005, 2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: PlotTests.java,v 1.1.2.1 2006/10/03 15:41:26 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 06-Jun-2005 : Version 1 (DG);
40  * 30-Jun-2006 : Extended equals() test to cover new field (DG);
41  *
42  */

43
44 package org.jfree.chart.plot.junit;
45
46 import java.awt.BasicStroke JavaDoc;
47 import java.awt.Color JavaDoc;
48 import java.awt.Font JavaDoc;
49 import java.awt.GradientPaint JavaDoc;
50 import java.awt.Paint JavaDoc;
51 import java.awt.Rectangle JavaDoc;
52 import java.awt.Shape JavaDoc;
53 import java.awt.Stroke JavaDoc;
54
55 import junit.framework.Test;
56 import junit.framework.TestCase;
57 import junit.framework.TestSuite;
58
59 import org.jfree.chart.JFreeChart;
60 import org.jfree.chart.plot.DefaultDrawingSupplier;
61 import org.jfree.chart.plot.PiePlot;
62 import org.jfree.chart.plot.Plot;
63 import org.jfree.ui.Align;
64 import org.jfree.ui.RectangleInsets;
65
66 /**
67  * Some tests for the {@link Plot} class.
68  */

69 public class PlotTests extends TestCase {
70
71     /**
72      * Returns the tests as a test suite.
73      *
74      * @return The test suite.
75      */

76     public static Test suite() {
77         return new TestSuite(PlotTests.class);
78     }
79
80     /**
81      * Constructs a new set of tests.
82      *
83      * @param name the name of the tests.
84      */

85     public PlotTests(String JavaDoc name) {
86         super(name);
87     }
88
89     /**
90      * Check that the equals() method can distinguish all fields (note that
91      * the dataset is NOT considered in the equals() method).
92      */

93     public void testEquals() {
94         PiePlot plot1 = new PiePlot();
95         PiePlot plot2 = new PiePlot();
96         assertTrue(plot1.equals(plot2));
97         assertTrue(plot2.equals(plot1));
98
99         // noDataMessage
100
plot1.setNoDataMessage("No data XYZ");
101         assertFalse(plot1.equals(plot2));
102         plot2.setNoDataMessage("No data XYZ");
103         assertTrue(plot1.equals(plot2));
104         
105         // noDataMessageFont
106
plot1.setNoDataMessageFont(new Font JavaDoc("SansSerif", Font.PLAIN, 13));
107         assertFalse(plot1.equals(plot2));
108         plot2.setNoDataMessageFont(new Font JavaDoc("SansSerif", Font.PLAIN, 13));
109         assertTrue(plot1.equals(plot2));
110         
111         // noDataMessagePaint
112
plot1.setNoDataMessagePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
113                 3.0f, 4.0f, Color.blue));
114         assertFalse(plot1.equals(plot2));
115         plot2.setNoDataMessagePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
116                 3.0f, 4.0f, Color.blue));
117         assertTrue(plot1.equals(plot2));
118         
119         // insets
120
plot1.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
121         assertFalse(plot1.equals(plot2));
122         plot2.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
123         assertTrue(plot1.equals(plot2));
124         
125         // outlineStroke
126
BasicStroke JavaDoc s = new BasicStroke JavaDoc(1.23f);
127         plot1.setOutlineStroke(s);
128         assertFalse(plot1.equals(plot2));
129         plot2.setOutlineStroke(s);
130         assertTrue(plot1.equals(plot2));
131         
132         // outlinePaint
133
plot1.setOutlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.yellow,
134                 3.0f, 4.0f, Color.green));
135         assertFalse(plot1.equals(plot2));
136         plot2.setOutlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.yellow,
137                 3.0f, 4.0f, Color.green));
138         assertTrue(plot1.equals(plot2));
139         
140         // backgroundPaint
141
plot1.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.cyan,
142                 3.0f, 4.0f, Color.green));
143         assertFalse(plot1.equals(plot2));
144         plot2.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.cyan,
145                 3.0f, 4.0f, Color.green));
146         assertTrue(plot1.equals(plot2));
147         
148         // backgroundImage
149
plot1.setBackgroundImage(JFreeChart.INFO.getLogo());
150         assertFalse(plot1.equals(plot2));
151         plot2.setBackgroundImage(JFreeChart.INFO.getLogo());
152         assertTrue(plot1.equals(plot2));
153         
154         // backgroundImageAlignment
155
plot1.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
156         assertFalse(plot1.equals(plot2));
157         plot2.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
158         assertTrue(plot1.equals(plot2));
159         
160         // backgroundImageAlpha
161
plot1.setBackgroundImageAlpha(0.77f);
162         assertFalse(plot1.equals(plot2));
163         plot2.setBackgroundImageAlpha(0.77f);
164         assertTrue(plot1.equals(plot2));
165         
166         // foregroundAlpha
167
plot1.setForegroundAlpha(0.99f);
168         assertFalse(plot1.equals(plot2));
169         plot2.setForegroundAlpha(0.99f);
170         assertTrue(plot1.equals(plot2));
171         
172         // backgroundAlpha
173
plot1.setBackgroundAlpha(0.99f);
174         assertFalse(plot1.equals(plot2));
175         plot2.setBackgroundAlpha(0.99f);
176         assertTrue(plot1.equals(plot2));
177         
178         // drawingSupplier
179
plot1.setDrawingSupplier(new DefaultDrawingSupplier(
180             new Paint JavaDoc[] {Color.blue}, new Paint JavaDoc[] {Color.red},
181             new Stroke JavaDoc[] {new BasicStroke JavaDoc(1.1f)},
182             new Stroke JavaDoc[] {new BasicStroke JavaDoc(9.9f)},
183             new Shape JavaDoc[] {new Rectangle JavaDoc(1, 2, 3, 4)}));
184         assertFalse(plot1.equals(plot2));
185         plot2.setDrawingSupplier(new DefaultDrawingSupplier(
186             new Paint JavaDoc[] {Color.blue}, new Paint JavaDoc[] {Color.red},
187             new Stroke JavaDoc[] {new BasicStroke JavaDoc(1.1f)},
188             new Stroke JavaDoc[] {new BasicStroke JavaDoc(9.9f)},
189             new Shape JavaDoc[] {new Rectangle JavaDoc(1, 2, 3, 4)}));
190         assertTrue(plot1.equals(plot2));
191     }
192     
193 }
194
Popular Tags