KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > text > junit > TextBoxTests


1 /* ========================================================================
2  * JCommon : a free general purpose class 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/jcommon/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  * TextBoxTests.java
29  * -----------------
30  * (C) Copyright 2004, 2005, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: TextBoxTests.java,v 1.5 2005/11/16 15:58:41 taqua Exp $
36  *
37  * Changes:
38  * --------
39  * 22-Mar-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.text.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.text.TextBlock;
59 import org.jfree.text.TextBox;
60 import org.jfree.text.TextLine;
61 import org.jfree.ui.RectangleInsets;
62
63 /**
64  * Tests for the {@link TextBox} class.
65  */

66 public class TextBoxTests 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(TextBoxTests.class);
75     }
76
77     /**
78      * Constructs a new set of tests.
79      *
80      * @param name the name of the tests.
81      */

82     public TextBoxTests(final 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         
91         final TextBox b1 = new TextBox("Hello");
92         final TextBox b2 = new TextBox("Hello");
93         assertTrue(b1.equals(b2));
94         assertTrue(b2.equals(b1));
95         
96         // outlinePaint
97
b1.setOutlinePaint(Color.blue);
98         assertFalse(b1.equals(b2));
99         b2.setOutlinePaint(Color.blue);
100         assertTrue(b1.equals(b2));
101
102         // outlineStroke
103
b1.setOutlineStroke(new BasicStroke JavaDoc(1.1f));
104         assertFalse(b1.equals(b2));
105         b2.setOutlineStroke(new BasicStroke JavaDoc(1.1f));
106         assertTrue(b1.equals(b2));
107
108         // interiorGap
109
b1.setInteriorGap(new RectangleInsets(10, 10, 10, 10));
110         assertFalse(b1.equals(b2));
111         b2.setInteriorGap(new RectangleInsets(10, 10, 10, 10));
112         assertTrue(b1.equals(b2));
113         
114         // backgroundPaint
115
b1.setBackgroundPaint(Color.blue);
116         assertFalse(b1.equals(b2));
117         b2.setBackgroundPaint(Color.blue);
118         assertTrue(b1.equals(b2));
119
120         // shadowPaint
121
b1.setShadowPaint(Color.blue);
122         assertFalse(b1.equals(b2));
123         b2.setShadowPaint(Color.blue);
124         assertTrue(b1.equals(b2));
125
126         // shadowXOffset
127
b1.setShadowXOffset(1.0);
128         assertFalse(b1.equals(b2));
129         b2.setShadowXOffset(1.0);
130         assertTrue(b1.equals(b2));
131         
132         // shadowYOffset
133
b1.setShadowYOffset(1.0);
134         assertFalse(b1.equals(b2));
135         b2.setShadowYOffset(1.0);
136         assertTrue(b1.equals(b2));
137         
138         // textBlock
139
final TextBlock tb1 = new TextBlock();
140         tb1.addLine(new TextLine("Testing"));
141         b1.setTextBlock(tb1);
142         assertFalse(b1.equals(b2));
143         final TextBlock tb2 = new TextBlock();
144         tb2.addLine(new TextLine("Testing"));
145         b2.setTextBlock(tb2);
146         assertTrue(b1.equals(b2));
147         
148     }
149
150     /**
151      * Serialize an instance, restore it, and check for equality.
152      */

153     public void testSerialization() {
154
155         final TextBox b1 = new TextBox("Hello");
156         TextBox b2 = null;
157
158         try {
159             final ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
160             final ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
161             out.writeObject(b1);
162             out.close();
163
164             final ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
165             b2 = (TextBox) in.readObject();
166             in.close();
167         }
168         catch (Exception JavaDoc e) {
169             System.out.println(e.toString());
170         }
171         assertEquals(b1, b2);
172
173     }
174
175 }
176
Popular Tags