001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2006, 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: * AbstractXYItemRendererTests.java
029: * --------------------------------
030: * (C) Copyright 2004, 2006, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: AbstractXYItemRendererTests.java,v 1.1.2.2 2006/11/24 16:36:33 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 06-Oct-2004 : Version 1 (DG);
040: * 24-Nov-2006 : Added cloning tests (DG);
041: *
042: */
043:
044: package org.jfree.chart.renderer.xy.junit;
045:
046: import junit.framework.Test;
047: import junit.framework.TestCase;
048: import junit.framework.TestSuite;
049:
050: import org.jfree.chart.labels.StandardXYSeriesLabelGenerator;
051: import org.jfree.chart.renderer.xy.AbstractXYItemRenderer;
052: import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
053: import org.jfree.chart.renderer.xy.XYBarRenderer;
054: import org.jfree.data.Range;
055: import org.jfree.data.xy.XYDataset;
056: import org.jfree.data.xy.XYSeries;
057: import org.jfree.data.xy.XYSeriesCollection;
058:
059: /**
060: * Tests for the {@link AbstractXYItemRenderer} class.
061: */
062: public class AbstractXYItemRendererTests extends TestCase {
063:
064: /**
065: * Returns the tests as a test suite.
066: *
067: * @return The test suite.
068: */
069: public static Test suite() {
070: return new TestSuite(AbstractXYItemRendererTests.class);
071: }
072:
073: /**
074: * Constructs a new set of tests.
075: *
076: * @param name the name of the tests.
077: */
078: public AbstractXYItemRendererTests(String name) {
079: super (name);
080: }
081:
082: /**
083: * Creates a test dataset.
084: *
085: * @return A test dataset.
086: */
087: private XYDataset createDataset1() {
088: XYSeries series = new XYSeries("Series");
089: series.add(1.0, 1.0);
090: series.add(2.0, 2.0);
091: series.add(3.0, 3.0);
092: XYSeriesCollection dataset = new XYSeriesCollection();
093: dataset.addSeries(series);
094: return dataset;
095: }
096:
097: private static final double EPSILON = 0.0000000001;
098:
099: /**
100: * Some checks for the findDomainBounds() method.
101: */
102: public void testFindDomainBounds() {
103: AbstractXYItemRenderer renderer = new StandardXYItemRenderer();
104:
105: // check the bounds of a simple dataset
106: XYDataset dataset = createDataset1();
107: Range r = renderer.findDomainBounds(dataset);
108: assertEquals(1.0, r.getLowerBound(), EPSILON);
109: assertEquals(3.0, r.getUpperBound(), EPSILON);
110:
111: // check that a null dataset returns null bounds
112: assertTrue(renderer.findDomainBounds(null) == null);
113: }
114:
115: /**
116: * Some checks for the findRangeBounds() method.
117: */
118: public void testFindRangeBounds() {
119: AbstractXYItemRenderer renderer = new StandardXYItemRenderer();
120: // check that a null dataset returns null bounds
121: assertTrue(renderer.findRangeBounds(null) == null);
122: }
123:
124: /**
125: * Check that the legendItemLabelGenerator is cloned.
126: */
127: public void testCloning_LegendItemLabelGenerator() {
128: StandardXYSeriesLabelGenerator generator = new StandardXYSeriesLabelGenerator(
129: "Series {0}");
130: XYBarRenderer r1 = new XYBarRenderer();
131: r1.setLegendItemLabelGenerator(generator);
132: XYBarRenderer r2 = null;
133: try {
134: r2 = (XYBarRenderer) r1.clone();
135: } catch (CloneNotSupportedException e) {
136: e.printStackTrace();
137: }
138: assertTrue(r1 != r2);
139: assertTrue(r1.getClass() == r2.getClass());
140: assertTrue(r1.equals(r2));
141:
142: // check that the generator has been cloned
143: assertTrue(r1.getLegendItemLabelGenerator() != r2
144: .getLegendItemLabelGenerator());
145: }
146:
147: /**
148: * Check that the legendItemToolTipGenerator is cloned.
149: */
150: public void testCloning_LegendItemToolTipGenerator() {
151: StandardXYSeriesLabelGenerator generator = new StandardXYSeriesLabelGenerator(
152: "Series {0}");
153: XYBarRenderer r1 = new XYBarRenderer();
154: r1.setLegendItemToolTipGenerator(generator);
155: XYBarRenderer r2 = null;
156: try {
157: r2 = (XYBarRenderer) r1.clone();
158: } catch (CloneNotSupportedException e) {
159: e.printStackTrace();
160: }
161: assertTrue(r1 != r2);
162: assertTrue(r1.getClass() == r2.getClass());
163: assertTrue(r1.equals(r2));
164:
165: // check that the generator has been cloned
166: assertTrue(r1.getLegendItemToolTipGenerator() != r2
167: .getLegendItemToolTipGenerator());
168: }
169:
170: /**
171: * Check that the legendItemURLGenerator is cloned.
172: */
173: public void testCloning_LegendItemURLGenerator() {
174: StandardXYSeriesLabelGenerator generator = new StandardXYSeriesLabelGenerator(
175: "Series {0}");
176: XYBarRenderer r1 = new XYBarRenderer();
177: r1.setLegendItemURLGenerator(generator);
178: XYBarRenderer r2 = null;
179: try {
180: r2 = (XYBarRenderer) r1.clone();
181: } catch (CloneNotSupportedException e) {
182: e.printStackTrace();
183: }
184: assertTrue(r1 != r2);
185: assertTrue(r1.getClass() == r2.getClass());
186: assertTrue(r1.equals(r2));
187:
188: // check that the generator has been cloned
189: assertTrue(r1.getLegendItemURLGenerator() != r2
190: .getLegendItemURLGenerator());
191: }
192:
193: }
|