KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > junit > MeterIntervalTests


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

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

64 public class MeterIntervalTests extends TestCase {
65
66     /**
67      * Returns the tests as a test suite.
68      *
69      * @return The test suite.
70      */

71     public static Test suite() {
72         return new TestSuite(MeterIntervalTests.class);
73     }
74
75     /**
76      * Constructs a new set of tests.
77      *
78      * @param name the name of the tests.
79      */

80     public MeterIntervalTests(String JavaDoc name) {
81         super(name);
82     }
83
84     /**
85      * Confirm that the equals method can distinguish all the required fields.
86      */

87     public void testEquals() {
88         
89         MeterInterval m1 = new MeterInterval(
90             "Label 1", new Range(1.2, 3.4), Color.red, new BasicStroke JavaDoc(1.0f),
91             Color.blue
92         );
93         MeterInterval m2 = new MeterInterval(
94             "Label 1", new Range(1.2, 3.4), Color.red, new BasicStroke JavaDoc(1.0f),
95             Color.blue
96         );
97         assertTrue(m1.equals(m2));
98         assertTrue(m2.equals(m1));
99         
100         m1 = new MeterInterval(
101             "Label 2", new Range(1.2, 3.4), Color.red, new BasicStroke JavaDoc(1.0f),
102             Color.blue
103         );
104         assertFalse(m1.equals(m2));
105         m2 = new MeterInterval(
106             "Label 2", new Range(1.2, 3.4), Color.red, new BasicStroke JavaDoc(1.0f),
107             Color.blue
108         );
109         assertTrue(m1.equals(m2));
110         
111     }
112         
113     /**
114      * This class is immutable so cloning isn't required.
115      */

116     public void testCloning() {
117         MeterInterval m1 = new MeterInterval("X", new Range(1.0, 2.0));
118         assertFalse(m1 instanceof Cloneable JavaDoc);
119     }
120
121    /**
122      * Serialize an instance, restore it, and check for equality.
123      */

124     public void testSerialization() {
125
126         MeterInterval m1 = new MeterInterval("X", new Range(1.0, 2.0));
127         MeterInterval m2 = null;
128         try {
129             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
130             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
131             out.writeObject(m1);
132             out.close();
133
134             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
135                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
136             );
137             m2 = (MeterInterval) in.readObject();
138             in.close();
139         }
140         catch (Exception JavaDoc e) {
141             System.out.println(e.toString());
142         }
143         boolean b = m1.equals(m2);
144         assertTrue(b);
145
146     }
147
148 }
149
Popular Tags