KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > junit > SpacerTests


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2004, 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 under the terms
10  * of the GNU Lesser General Public License as published by the Free Software Foundation;
11  * either version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License along with this
18  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
22  * in the United States and other countries.]
23  *
24  * ----------------
25  * SpacerTests.java
26  * ----------------
27  * (C) Copyright 2003, 2004, by Object Refinery Limited and Contributors.
28  *
29  * Original Author: David Gilbert (for Object Refinery Limited);
30  * Contributor(s): -;
31  *
32  * $Id: SpacerTests.java,v 1.2 2004/11/10 21:44:22 mungady Exp $
33  *
34  * Changes
35  * -------
36  * 18-Aug-2003 : Version 1 (DG);
37  *
38  */

39
40 package org.jfree.ui.junit;
41
42 import java.io.ByteArrayInputStream JavaDoc;
43 import java.io.ByteArrayOutputStream JavaDoc;
44 import java.io.ObjectInput JavaDoc;
45 import java.io.ObjectInputStream JavaDoc;
46 import java.io.ObjectOutput JavaDoc;
47 import java.io.ObjectOutputStream JavaDoc;
48
49 import junit.framework.Test;
50 import junit.framework.TestCase;
51 import junit.framework.TestSuite;
52
53 import org.jfree.ui.Spacer;
54
55 /**
56  * Tests for the {@link Spacer} class.
57  */

58 public class SpacerTests extends TestCase {
59
60     /**
61      * Returns the tests as a test suite.
62      *
63      * @return The test suite.
64      */

65     public static Test suite() {
66         return new TestSuite(SpacerTests.class);
67     }
68
69     /**
70      * Constructs a new set of tests.
71      *
72      * @param name the name of the tests.
73      */

74     public SpacerTests(final String JavaDoc name) {
75         super(name);
76     }
77
78     /**
79      * Confirm that the equals method can distinguish all the required fields.
80      */

81     public void testEquals() {
82         
83         Spacer s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
84         Spacer s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
85         assertTrue(s1.equals(s2));
86         
87         s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
88         s2 = new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05);
89         assertFalse(s1.equals(s2));
90
91         s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
92         s2 = new Spacer(Spacer.ABSOLUTE, 0.06, 0.05, 0.05, 0.05);
93         assertFalse(s1.equals(s2));
94
95         s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
96         s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.06, 0.05, 0.05);
97         assertFalse(s1.equals(s2));
98
99         s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
100         s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.06, 0.05);
101         assertFalse(s1.equals(s2));
102
103         s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
104         s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.06);
105         assertFalse(s1.equals(s2));
106         
107     }
108         
109     /**
110      * Serialize an instance, restore it, and check for equality.
111      */

112     public void testSerialization() {
113
114         final Spacer s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
115         Spacer s2 = null;
116
117         try {
118             final ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
119             final ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
120             out.writeObject(s1);
121             out.close();
122
123             final ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
124             s2 = (Spacer) in.readObject();
125             in.close();
126         }
127         catch (Exception JavaDoc e) {
128             System.out.println(e.toString());
129         }
130         final boolean b = s1.equals(s2);
131         assertTrue(b);
132
133     }
134
135 }
136
Popular Tags