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: * PlotTests.java
029: * --------------
030: * (C) Copyright 2005-2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: PlotTests.java,v 1.1.2.2 2007/06/13 10:24:51 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 06-Jun-2005 : Version 1 (DG);
040: * 30-Jun-2006 : Extended equals() test to cover new field (DG);
041: * 11-May-2007 : Another new field in testEquals() (DG);
042: *
043: */
044:
045: package org.jfree.chart.plot.junit;
046:
047: import java.awt.BasicStroke;
048: import java.awt.Color;
049: import java.awt.Font;
050: import java.awt.GradientPaint;
051: import java.awt.Paint;
052: import java.awt.Rectangle;
053: import java.awt.Shape;
054: import java.awt.Stroke;
055:
056: import junit.framework.Test;
057: import junit.framework.TestCase;
058: import junit.framework.TestSuite;
059:
060: import org.jfree.chart.JFreeChart;
061: import org.jfree.chart.plot.DefaultDrawingSupplier;
062: import org.jfree.chart.plot.PiePlot;
063: import org.jfree.chart.plot.Plot;
064: import org.jfree.ui.Align;
065: import org.jfree.ui.RectangleInsets;
066:
067: /**
068: * Some tests for the {@link Plot} class.
069: */
070: public class PlotTests extends TestCase {
071:
072: /**
073: * Returns the tests as a test suite.
074: *
075: * @return The test suite.
076: */
077: public static Test suite() {
078: return new TestSuite(PlotTests.class);
079: }
080:
081: /**
082: * Constructs a new set of tests.
083: *
084: * @param name the name of the tests.
085: */
086: public PlotTests(String name) {
087: super (name);
088: }
089:
090: /**
091: * Check that the equals() method can distinguish all fields (note that
092: * the dataset is NOT considered in the equals() method).
093: */
094: public void testEquals() {
095: PiePlot plot1 = new PiePlot();
096: PiePlot plot2 = new PiePlot();
097: assertTrue(plot1.equals(plot2));
098: assertTrue(plot2.equals(plot1));
099:
100: // noDataMessage
101: plot1.setNoDataMessage("No data XYZ");
102: assertFalse(plot1.equals(plot2));
103: plot2.setNoDataMessage("No data XYZ");
104: assertTrue(plot1.equals(plot2));
105:
106: // noDataMessageFont
107: plot1
108: .setNoDataMessageFont(new Font("SansSerif", Font.PLAIN,
109: 13));
110: assertFalse(plot1.equals(plot2));
111: plot2
112: .setNoDataMessageFont(new Font("SansSerif", Font.PLAIN,
113: 13));
114: assertTrue(plot1.equals(plot2));
115:
116: // noDataMessagePaint
117: plot1.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f,
118: Color.red, 3.0f, 4.0f, Color.blue));
119: assertFalse(plot1.equals(plot2));
120: plot2.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f,
121: Color.red, 3.0f, 4.0f, Color.blue));
122: assertTrue(plot1.equals(plot2));
123:
124: // insets
125: plot1.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
126: assertFalse(plot1.equals(plot2));
127: plot2.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
128: assertTrue(plot1.equals(plot2));
129:
130: // outlineVisible
131: plot1.setOutlineVisible(false);
132: assertFalse(plot1.equals(plot2));
133: plot2.setOutlineVisible(false);
134: assertTrue(plot1.equals(plot2));
135:
136: // outlineStroke
137: BasicStroke s = new BasicStroke(1.23f);
138: plot1.setOutlineStroke(s);
139: assertFalse(plot1.equals(plot2));
140: plot2.setOutlineStroke(s);
141: assertTrue(plot1.equals(plot2));
142:
143: // outlinePaint
144: plot1.setOutlinePaint(new GradientPaint(1.0f, 2.0f,
145: Color.yellow, 3.0f, 4.0f, Color.green));
146: assertFalse(plot1.equals(plot2));
147: plot2.setOutlinePaint(new GradientPaint(1.0f, 2.0f,
148: Color.yellow, 3.0f, 4.0f, Color.green));
149: assertTrue(plot1.equals(plot2));
150:
151: // backgroundPaint
152: plot1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f,
153: Color.cyan, 3.0f, 4.0f, Color.green));
154: assertFalse(plot1.equals(plot2));
155: plot2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f,
156: Color.cyan, 3.0f, 4.0f, Color.green));
157: assertTrue(plot1.equals(plot2));
158:
159: // backgroundImage
160: plot1.setBackgroundImage(JFreeChart.INFO.getLogo());
161: assertFalse(plot1.equals(plot2));
162: plot2.setBackgroundImage(JFreeChart.INFO.getLogo());
163: assertTrue(plot1.equals(plot2));
164:
165: // backgroundImageAlignment
166: plot1.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
167: assertFalse(plot1.equals(plot2));
168: plot2.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
169: assertTrue(plot1.equals(plot2));
170:
171: // backgroundImageAlpha
172: plot1.setBackgroundImageAlpha(0.77f);
173: assertFalse(plot1.equals(plot2));
174: plot2.setBackgroundImageAlpha(0.77f);
175: assertTrue(plot1.equals(plot2));
176:
177: // foregroundAlpha
178: plot1.setForegroundAlpha(0.99f);
179: assertFalse(plot1.equals(plot2));
180: plot2.setForegroundAlpha(0.99f);
181: assertTrue(plot1.equals(plot2));
182:
183: // backgroundAlpha
184: plot1.setBackgroundAlpha(0.99f);
185: assertFalse(plot1.equals(plot2));
186: plot2.setBackgroundAlpha(0.99f);
187: assertTrue(plot1.equals(plot2));
188:
189: // drawingSupplier
190: plot1.setDrawingSupplier(new DefaultDrawingSupplier(
191: new Paint[] { Color.blue }, new Paint[] { Color.red },
192: new Stroke[] { new BasicStroke(1.1f) },
193: new Stroke[] { new BasicStroke(9.9f) },
194: new Shape[] { new Rectangle(1, 2, 3, 4) }));
195: assertFalse(plot1.equals(plot2));
196: plot2.setDrawingSupplier(new DefaultDrawingSupplier(
197: new Paint[] { Color.blue }, new Paint[] { Color.red },
198: new Stroke[] { new BasicStroke(1.1f) },
199: new Stroke[] { new BasicStroke(9.9f) },
200: new Shape[] { new Rectangle(1, 2, 3, 4) }));
201: assertTrue(plot1.equals(plot2));
202: }
203:
204: }
|