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: * WaterfallChartTests.java
029: * ------------------------
030: * (C) Copyright 2002-2007, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: WaterfallChartTests.java,v 1.1.2.2 2007/03/02 11:16:20 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 12-Apr-2005 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.chart.junit;
044:
045: import java.awt.Graphics2D;
046: import java.awt.geom.Rectangle2D;
047: import java.awt.image.BufferedImage;
048:
049: import junit.framework.Test;
050: import junit.framework.TestCase;
051: import junit.framework.TestSuite;
052:
053: import org.jfree.chart.ChartFactory;
054: import org.jfree.chart.JFreeChart;
055: import org.jfree.chart.labels.CategoryToolTipGenerator;
056: import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
057: import org.jfree.chart.plot.CategoryPlot;
058: import org.jfree.chart.plot.PlotOrientation;
059: import org.jfree.chart.renderer.category.CategoryItemRenderer;
060: import org.jfree.chart.urls.CategoryURLGenerator;
061: import org.jfree.chart.urls.StandardCategoryURLGenerator;
062: import org.jfree.data.category.CategoryDataset;
063: import org.jfree.data.general.DatasetUtilities;
064:
065: /**
066: * Some tests for a waterfall chart.
067: */
068: public class WaterfallChartTests extends TestCase {
069:
070: /** A chart. */
071: private JFreeChart chart;
072:
073: /**
074: * Returns the tests as a test suite.
075: *
076: * @return The test suite.
077: */
078: public static Test suite() {
079: return new TestSuite(WaterfallChartTests.class);
080: }
081:
082: /**
083: * Constructs a new set of tests.
084: *
085: * @param name the name of the tests.
086: */
087: public WaterfallChartTests(String name) {
088: super (name);
089: }
090:
091: /**
092: * Common test setup.
093: */
094: protected void setUp() {
095: this .chart = createWaterfallChart();
096: }
097:
098: /**
099: * Draws the chart with a null info object to make sure that no exceptions
100: * are thrown (a problem that was occurring at one point).
101: */
102: public void testDrawWithNullInfo() {
103:
104: boolean success = false;
105:
106: try {
107: BufferedImage image = new BufferedImage(200, 100,
108: BufferedImage.TYPE_INT_RGB);
109: Graphics2D g2 = image.createGraphics();
110: this .chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100),
111: null, null);
112: g2.dispose();
113: success = true;
114: } catch (Exception e) {
115: success = false;
116: }
117:
118: assertTrue(success);
119:
120: }
121:
122: /**
123: * Check that setting a tool tip generator for a series does override the
124: * default generator.
125: */
126: public void testSetSeriesToolTipGenerator() {
127: CategoryPlot plot = (CategoryPlot) this .chart.getPlot();
128: CategoryItemRenderer renderer = plot.getRenderer();
129: StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator();
130: renderer.setSeriesToolTipGenerator(0, tt);
131: CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0,
132: 0);
133: assertTrue(tt2 == tt);
134: }
135:
136: /**
137: * Check that setting a URL generator for a series does override the
138: * default generator.
139: */
140: public void testSetSeriesURLGenerator() {
141: CategoryPlot plot = (CategoryPlot) this .chart.getPlot();
142: CategoryItemRenderer renderer = plot.getRenderer();
143: StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator();
144: renderer.setSeriesItemURLGenerator(0, url1);
145: CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0);
146: assertTrue(url2 == url1);
147: }
148:
149: /**
150: * Create a bar chart with sample data in the range -3 to +3.
151: *
152: * @return The chart.
153: */
154: private static JFreeChart createWaterfallChart() {
155:
156: // create a dataset...
157: Number[][] data = new Integer[][] {
158: { new Integer(-3), new Integer(-2) },
159: { new Integer(-1), new Integer(1) },
160: { new Integer(2), new Integer(3) } };
161:
162: CategoryDataset dataset = DatasetUtilities
163: .createCategoryDataset("S", "C", data);
164:
165: // create the chart...
166: return ChartFactory.createWaterfallChart("Waterfall Chart",
167: "Domain", "Range", dataset, PlotOrientation.HORIZONTAL,
168: true, // include legend
169: true, true);
170:
171: }
172:
173: }
|