KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LabelBlockTests.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: LabelBlockTests.java,v 1.1.2.1 2006/10/03 15:41:44 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 01-Sep-2005 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.block.junit;
44
45 import java.awt.Color JavaDoc;
46 import java.awt.Font 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.block.LabelBlock;
59
60 /**
61  * Some tests for the {@link LabelBlock} class.
62  */

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

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

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

86     public void testEquals() {
87         LabelBlock b1 = new LabelBlock("ABC", new Font JavaDoc("Dialog",
88                 Font.PLAIN, 12), Color.red);
89         LabelBlock b2 = new LabelBlock("ABC", new Font JavaDoc("Dialog",
90                 Font.PLAIN, 12), Color.red);
91         assertTrue(b1.equals(b2));
92         assertTrue(b2.equals(b2));
93         
94         b1 = new LabelBlock("XYZ", new Font JavaDoc("Dialog", Font.PLAIN, 12),
95                 Color.red);
96         assertFalse(b1.equals(b2));
97         b2 = new LabelBlock("XYZ", new Font JavaDoc("Dialog", Font.PLAIN, 12),
98                 Color.red);
99         assertTrue(b1.equals(b2));
100
101         b1 = new LabelBlock("XYZ", new Font JavaDoc("Dialog", Font.BOLD, 12),
102                 Color.red);
103         assertFalse(b1.equals(b2));
104         b2 = new LabelBlock("XYZ", new Font JavaDoc("Dialog", Font.BOLD, 12),
105                 Color.red);
106         assertTrue(b1.equals(b2));
107
108         b1 = new LabelBlock("XYZ", new Font JavaDoc("Dialog", Font.BOLD, 12),
109                 Color.blue);
110         assertFalse(b1.equals(b2));
111         b2 = new LabelBlock("XYZ", new Font JavaDoc("Dialog", Font.BOLD, 12),
112                 Color.blue);
113         assertTrue(b1.equals(b2));
114         
115         b1.setToolTipText("Tooltip");
116         assertFalse(b1.equals(b2));
117         b2.setToolTipText("Tooltip");
118         assertTrue(b1.equals(b2));
119         
120         b1.setURLText("URL");
121         assertFalse(b1.equals(b2));
122         b2.setURLText("URL");
123         assertTrue(b1.equals(b2));
124     }
125
126     /**
127      * Confirm that cloning works.
128      */

129     public void testCloning() {
130         LabelBlock b1 = new LabelBlock("ABC", new Font JavaDoc("Dialog",
131                 Font.PLAIN, 12), Color.red);
132         LabelBlock b2 = null;
133         
134         try {
135             b2 = (LabelBlock) b1.clone();
136         }
137         catch (CloneNotSupportedException JavaDoc e) {
138             fail(e.toString());
139         }
140         assertTrue(b1 != b2);
141         assertTrue(b1.getClass() == b2.getClass());
142         assertTrue(b1.equals(b2));
143     }
144
145     /**
146      * Serialize an instance, restore it, and check for equality.
147      */

148     public void testSerialization() {
149         LabelBlock b1 = new LabelBlock("ABC", new Font JavaDoc("Dialog",
150                 Font.PLAIN, 12), Color.red);
151         LabelBlock b2 = null;
152         try {
153             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
154             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
155             out.writeObject(b1);
156             out.close();
157
158             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
159                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
160             );
161             b2 = (LabelBlock) in.readObject();
162             in.close();
163         }
164         catch (Exception JavaDoc e) {
165             fail(e.toString());
166         }
167         assertEquals(b1, b2);
168     }
169    
170 }
171
Popular Tags