KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > category > junit > AbstractCategoryItemRendererTests


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

42
43 package org.jfree.chart.renderer.category.junit;
44
45 import junit.framework.Test;
46 import junit.framework.TestCase;
47 import junit.framework.TestSuite;
48
49 import org.jfree.chart.labels.IntervalCategoryItemLabelGenerator;
50 import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
51 import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer;
52 import org.jfree.chart.renderer.category.BarRenderer;
53
54 /**
55  * Tests for the {@link AbstractCategoryItemRenderer} class.
56  *
57  */

58 public class AbstractCategoryItemRendererTests extends TestCase {
59
60     /**
61      * Returns the tests as a test suite.
62      *
63      * @return The test suite.
64      */

65     public static Test suite() {
66         return new TestSuite(AbstractCategoryItemRendererTests.class);
67     }
68
69     /**
70      * Confirm that cloning works.
71      */

72     public void testCloning1() {
73         
74         AbstractCategoryItemRenderer r1 = new BarRenderer();
75         r1.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
76         AbstractCategoryItemRenderer r2 = null;
77         try {
78             r2 = (BarRenderer) r1.clone();
79         }
80         catch (CloneNotSupportedException JavaDoc e) {
81             System.err.println("Failed to clone.");
82         }
83         assertTrue(r1 != r2);
84         assertTrue(r1.getClass() == r2.getClass());
85         assertTrue(r1.equals(r2));
86         
87         r1 = new BarRenderer();
88         r1.setSeriesItemLabelGenerator(
89             0, new StandardCategoryItemLabelGenerator()
90         );
91         r2 = null;
92         try {
93             r2 = (BarRenderer) r1.clone();
94         }
95         catch (CloneNotSupportedException JavaDoc e) {
96             System.err.println("Failed to clone.");
97         }
98         assertTrue(r1 != r2);
99         assertTrue(r1.getClass() == r2.getClass());
100         assertTrue(r1.equals(r2));
101         
102         r1 = new BarRenderer();
103         r1.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
104         r2 = null;
105         try {
106             r2 = (BarRenderer) r1.clone();
107         }
108         catch (CloneNotSupportedException JavaDoc e) {
109             System.err.println("Failed to clone.");
110         }
111         assertTrue(r1 != r2);
112         assertTrue(r1.getClass() == r2.getClass());
113         assertTrue(r1.equals(r2));
114     }
115     
116     /**
117      * Confirm that cloning works.
118      */

119     public void testCloning2() {
120         
121         BarRenderer r1 = new BarRenderer();
122         r1.setItemLabelGenerator(new IntervalCategoryItemLabelGenerator());
123         BarRenderer r2 = null;
124         try {
125             r2 = (BarRenderer) r1.clone();
126         }
127         catch (CloneNotSupportedException JavaDoc e) {
128             System.err.println("Failed to clone.");
129         }
130         assertTrue(r1 != r2);
131         assertTrue(r1.getClass() == r2.getClass());
132         assertTrue(r1.equals(r2));
133         
134         r1 = new BarRenderer();
135         r1.setSeriesItemLabelGenerator(
136             0, new IntervalCategoryItemLabelGenerator()
137         );
138         r2 = null;
139         try {
140             r2 = (BarRenderer) r1.clone();
141         }
142         catch (CloneNotSupportedException JavaDoc e) {
143             System.err.println("Failed to clone.");
144         }
145         assertTrue(r1 != r2);
146         assertTrue(r1.getClass() == r2.getClass());
147         assertTrue(r1.equals(r2));
148         
149         r1 = new BarRenderer();
150         r1.setBaseItemLabelGenerator(new IntervalCategoryItemLabelGenerator());
151         r2 = null;
152         try {
153             r2 = (BarRenderer) r1.clone();
154         }
155         catch (CloneNotSupportedException JavaDoc e) {
156             System.err.println("Failed to clone.");
157         }
158         assertTrue(r1 != r2);
159         assertTrue(r1.getClass() == r2.getClass());
160         assertTrue(r1.equals(r2));
161     }
162
163 }
164     
165
Popular Tags