KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > block > junit > BlockBorderTests


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  * BlockBorderTests.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: BlockBorderTests.java,v 1.1.2.1 2006/10/03 15:41:45 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 04-Feb-2005 : Version 1 (DG);
40  * 23-Feb-2005 : Extended equals() test (DG);
41  *
42  */

43
44 package org.jfree.chart.block.junit;
45
46 import java.awt.Color JavaDoc;
47 import java.awt.GradientPaint JavaDoc;
48 import java.io.ByteArrayInputStream JavaDoc;
49 import java.io.ByteArrayOutputStream JavaDoc;
50 import java.io.ObjectInput JavaDoc;
51 import java.io.ObjectInputStream JavaDoc;
52 import java.io.ObjectOutput JavaDoc;
53 import java.io.ObjectOutputStream JavaDoc;
54
55 import junit.framework.Test;
56 import junit.framework.TestCase;
57 import junit.framework.TestSuite;
58
59 import org.jfree.chart.block.BlockBorder;
60 import org.jfree.ui.RectangleInsets;
61 import org.jfree.util.UnitType;
62
63 /**
64  * Tests for the {@link BlockBorder} class.
65  */

66 public class BlockBorderTests extends TestCase {
67     
68     /**
69      * Returns the tests as a test suite.
70      *
71      * @return The test suite.
72      */

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

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

89     public void testEquals() {
90         BlockBorder b1 = new BlockBorder(
91             new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.red
92         );
93         BlockBorder b2 = new BlockBorder(
94             new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.red
95         );
96         assertTrue(b1.equals(b2));
97         assertTrue(b2.equals(b2));
98         
99         // insets
100
b1 = new BlockBorder(
101             new RectangleInsets(UnitType.RELATIVE, 1.0, 2.0, 3.0, 4.0),
102             Color.red
103         );
104         assertFalse(b1.equals(b2));
105         b2 = new BlockBorder(
106             new RectangleInsets(UnitType.RELATIVE, 1.0, 2.0, 3.0, 4.0),
107             Color.red
108         );
109         assertTrue(b1.equals(b2));
110         
111         // paint
112
b1 = new BlockBorder(
113             new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.blue
114         );
115         assertFalse(b1.equals(b2));
116         b2 = new BlockBorder(
117             new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.blue
118         );
119         assertTrue(b1.equals(b2));
120     }
121
122     /**
123      * Immutable - cloning not necessary.
124      */

125     public void testCloning() {
126         BlockBorder b1 = new BlockBorder();
127         assertFalse(b1 instanceof Cloneable JavaDoc);
128     }
129
130     /**
131      * Serialize an instance, restore it, and check for equality.
132      */

133     public void testSerialization() {
134         BlockBorder b1 = new BlockBorder(
135             new RectangleInsets(1.0, 2.0, 3.0, 4.0),
136             new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)
137         );
138         BlockBorder b2 = null;
139         try {
140             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
141             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
142             out.writeObject(b1);
143             out.close();
144
145             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
146                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
147             );
148             b2 = (BlockBorder) in.readObject();
149             in.close();
150         }
151         catch (Exception JavaDoc e) {
152             fail(e.toString());
153         }
154         assertTrue(b1.equals(b2));
155     }
156    
157 }
158
Popular Tags