KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MeterChartTests.java
29  * --------------------
30  * (C) Copyright 2005, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: MeterChartTests.java,v 1.1.2.1 2006/10/03 15:41:29 mungady Exp $
36  *
37  * Changes:
38  * --------
39  * 29-Mar-2005 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.junit;
44
45 import java.awt.Graphics2D JavaDoc;
46 import java.awt.geom.Rectangle2D JavaDoc;
47 import java.awt.image.BufferedImage JavaDoc;
48
49 import junit.framework.Test;
50 import junit.framework.TestCase;
51 import junit.framework.TestSuite;
52
53 import org.jfree.chart.JFreeChart;
54 import org.jfree.chart.plot.MeterInterval;
55 import org.jfree.chart.plot.MeterPlot;
56 import org.jfree.data.Range;
57 import org.jfree.data.general.DefaultValueDataset;
58
59 /**
60  * Miscellaneous checks for meter charts.
61  */

62 public class MeterChartTests extends TestCase {
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(MeterChartTests.class);
71     }
72
73     /**
74      * Constructs a new set of tests.
75      *
76      * @param name the name of the tests.
77      */

78     public MeterChartTests(String JavaDoc name) {
79         super(name);
80     }
81
82     /**
83      * Draws the chart with a single range. At one point, this caused a null
84      * pointer exception (fixed now).
85      */

86     public void testDrawWithNullInfo() {
87         boolean success = false;
88         MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0));
89         plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0)));
90         JFreeChart chart = new JFreeChart(plot);
91         try {
92             BufferedImage JavaDoc image = new BufferedImage JavaDoc(
93                 200, 100, BufferedImage.TYPE_INT_RGB
94             );
95             Graphics2D JavaDoc g2 = image.createGraphics();
96             chart.draw(
97                 g2, new Rectangle2D.Double JavaDoc(0, 0, 200, 100), null, null
98             );
99             g2.dispose();
100             success = true;
101         }
102         catch (Exception JavaDoc e) {
103             success = false;
104         }
105         assertTrue(success);
106     }
107
108 }
109
Popular Tags