KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > experimental > chart > renderer > junit > GrayPaintScaleTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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  * GrayPaintScaleTests.java
29  * ------------------------
30  * (C) Copyright 2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: GrayPaintScaleTests.java,v 1.1.2.1 2006/10/12 10:58:44 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 05-Jul-2006 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.experimental.chart.renderer.junit;
44
45 import java.io.ByteArrayInputStream JavaDoc;
46 import java.io.ByteArrayOutputStream JavaDoc;
47 import java.io.ObjectInput JavaDoc;
48 import java.io.ObjectInputStream JavaDoc;
49 import java.io.ObjectOutput JavaDoc;
50 import java.io.ObjectOutputStream JavaDoc;
51
52 import org.jfree.experimental.chart.renderer.GrayPaintScale;
53
54 import junit.framework.Test;
55 import junit.framework.TestCase;
56 import junit.framework.TestSuite;
57
58
59 /**
60  * Tests for the {@link GrayPaintScale} class.
61  */

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

78     public GrayPaintScaleTests(String JavaDoc name) {
79         super(name);
80     }
81     
82     /**
83      * A test for the equals() method.
84      */

85     public void testEquals() {
86         GrayPaintScale g1 = new GrayPaintScale();
87         GrayPaintScale g2 = new GrayPaintScale();
88         assertTrue(g1.equals(g2));
89         assertTrue(g2.equals(g1));
90         
91         g1 = new GrayPaintScale(0.0, 1.0);
92         g2 = new GrayPaintScale(0.0, 1.0);
93         assertTrue(g1.equals(g2));
94         g1 = new GrayPaintScale(0.1, 1.0);
95         assertFalse(g1.equals(g2));
96         g2 = new GrayPaintScale(0.1, 1.0);
97         assertTrue(g1.equals(g2));
98         
99         g1 = new GrayPaintScale(0.1, 0.9);
100         assertFalse(g1.equals(g2));
101         g2 = new GrayPaintScale(0.1, 0.9);
102         assertTrue(g1.equals(g2));
103     }
104     
105     /**
106      * Confirm that cloning works.
107      */

108     public void testCloning() {
109         GrayPaintScale g1 = new GrayPaintScale();
110         GrayPaintScale g2 = null;
111         try {
112             g2 = (GrayPaintScale) g1.clone();
113         }
114         catch (CloneNotSupportedException JavaDoc e) {
115             e.printStackTrace();
116         }
117         assertTrue(g1 != g2);
118         assertTrue(g1.getClass() == g2.getClass());
119         assertTrue(g1.equals(g2));
120     }
121     
122     /**
123      * Serialize an instance, restore it, and check for equality.
124      */

125     public void testSerialization() {
126         GrayPaintScale g1 = new GrayPaintScale();
127         GrayPaintScale g2 = null;
128         try {
129             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
130             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
131             out.writeObject(g1);
132             out.close();
133
134             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
135                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
136             g2 = (GrayPaintScale) in.readObject();
137             in.close();
138         }
139         catch (Exception JavaDoc e) {
140             e.printStackTrace();
141         }
142         assertEquals(g1, g2);
143     }
144
145 }
146
Popular Tags