KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > junit > MarkerAxisBandTests


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ------------------------
27  * MarkerAxisBandTests.java
28  * ------------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: MarkerAxisBandTests.java,v 1.3 2005/03/16 12:10:45 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 26-Mar-2003 : Version 1 (DG);
39  * 07-Jan-2005 : Added tests for equals() and hashCode() (DG);
40  *
41  */

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

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

78     public MarkerAxisBandTests(String JavaDoc name) {
79         super(name);
80     }
81
82     /**
83      * Test that the equals() method can distinguish all fields.
84      */

85     public void testEquals() {
86         Font JavaDoc font1 = new Font JavaDoc("SansSerif", Font.PLAIN, 12);
87         Font JavaDoc font2 = new Font JavaDoc("SansSerif", Font.PLAIN, 14);
88         
89         MarkerAxisBand a1 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1);
90         MarkerAxisBand a2 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1);
91         assertEquals(a1, a2);
92         
93         a1 = new MarkerAxisBand(null, 2.0, 1.0, 1.0, 1.0, font1);
94         assertFalse(a1.equals(a2));
95         a2 = new MarkerAxisBand(null, 2.0, 1.0, 1.0, 1.0, font1);
96         assertTrue(a1.equals(a2));
97         
98         a1 = new MarkerAxisBand(null, 2.0, 3.0, 1.0, 1.0, font1);
99         assertFalse(a1.equals(a2));
100         a2 = new MarkerAxisBand(null, 2.0, 3.0, 1.0, 1.0, font1);
101         assertTrue(a1.equals(a2));
102         
103         a1 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 1.0, font1);
104         assertFalse(a1.equals(a2));
105         a2 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 1.0, font1);
106         assertTrue(a1.equals(a2));
107
108         a1 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font1);
109         assertFalse(a1.equals(a2));
110         a2 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font1);
111         assertTrue(a1.equals(a2));
112
113         a1 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font2);
114         assertFalse(a1.equals(a2));
115         a2 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font2);
116         assertTrue(a1.equals(a2));
117     }
118     
119     /**
120      * Two objects that are equal are required to return the same hashCode.
121      */

122     public void testHashCode() {
123         Font JavaDoc font1 = new Font JavaDoc("SansSerif", Font.PLAIN, 12);
124         
125         MarkerAxisBand a1 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1);
126         MarkerAxisBand a2 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1);
127          assertTrue(a1.equals(a2));
128         int h1 = a1.hashCode();
129         int h2 = a2.hashCode();
130         assertEquals(h1, h2);
131     }
132
133     /**
134      * Serialize an instance, restore it, and check for equality.
135      */

136     public void testSerialization() {
137
138         MarkerAxisBand a1 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, null);
139         MarkerAxisBand a2 = null;
140
141         try {
142             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
143             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
144             out.writeObject(a1);
145             out.close();
146
147             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
148                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
149             );
150             a2 = (MarkerAxisBand) in.readObject();
151             in.close();
152         }
153         catch (Exception JavaDoc e) {
154             System.out.println(e.toString());
155         }
156         assertEquals(a1, a2);
157
158     }
159
160 }
161
Popular Tags