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 * BlockContainerTests.java
28 * ------------------------
29 * (C) Copyright 2005, by Object Refinery Limited and Contributors.
30 *
31 * Original Author: David Gilbert (for Object Refinery Limited);
32 * Contributor(s): -;
33 *
34 * $Id: EmptyBlockTests.java,v 1.1 2005/02/04 16:55:15 mungady Exp $
35 *
36 * Changes
37 * -------
38 * 04-Feb-2005 : Version 1 (DG);
39 *
40 */
41
42 package org.jfree.chart.block.junit;
43
44 import java.io.ByteArrayInputStream;
45 import java.io.ByteArrayOutputStream;
46 import java.io.ObjectInput;
47 import java.io.ObjectInputStream;
48 import java.io.ObjectOutput;
49 import java.io.ObjectOutputStream;
50
51 import junit.framework.Test;
52 import junit.framework.TestCase;
53 import junit.framework.TestSuite;
54
55 import org.jfree.chart.block.EmptyBlock;
56
57 /**
58 * Tests for the {@link EmptyBlock} class.
59 */
60 public class EmptyBlockTests extends TestCase {
61
62 /**
63 * Returns the tests as a test suite.
64 *
65 * @return The test suite.
66 */
67 public static Test suite() {
68 return new TestSuite(EmptyBlockTests.class);
69 }
70
71 /**
72 * Constructs a new set of tests.
73 *
74 * @param name the name of the tests.
75 */
76 public EmptyBlockTests(String name) {
77 super(name);
78 }
79
80 /**
81 * Confirm that the equals() method can distinguish all the required fields.
82 */
83 public void testEquals() {
84 EmptyBlock b1 = new EmptyBlock(1.0, 2.0);
85 EmptyBlock b2 = new EmptyBlock(1.0, 2.0);
86 assertTrue(b1.equals(b2));
87 assertTrue(b2.equals(b2));
88
89 b1 = new EmptyBlock(1.1, 2.0);
90 assertFalse(b1.equals(b2));
91 b2 = new EmptyBlock(1.1, 2.0);
92 assertTrue(b1.equals(b2));
93
94 b1 = new EmptyBlock(1.1, 2.2);
95 assertFalse(b1.equals(b2));
96 b2 = new EmptyBlock(1.1, 2.2);
97 assertTrue(b1.equals(b2));
98 }
99
100 /**
101 * Confirm that cloning works.
102 */
103 public void testCloning() {
104 EmptyBlock b1 = new EmptyBlock(1.0, 2.0);
105 EmptyBlock b2 = null;
106
107 try {
108 b2 = (EmptyBlock) b1.clone();
109 }
110 catch (CloneNotSupportedException e) {
111 fail(e.toString());
112 }
113 assertTrue(b1 != b2);
114 assertTrue(b1.getClass() == b2.getClass());
115 assertTrue(b1.equals(b2));
116 }
117
118 /**
119 * Serialize an instance, restore it, and check for equality.
120 */
121 public void testSerialization() {
122 EmptyBlock b1 = new EmptyBlock(1.0, 2.0);
123 EmptyBlock b2 = null;
124 try {
125 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
126 ObjectOutput out = new ObjectOutputStream(buffer);
127 out.writeObject(b1);
128 out.close();
129
130 ObjectInput in = new ObjectInputStream(
131 new ByteArrayInputStream(buffer.toByteArray())
132 );
133 b2 = (EmptyBlock) in.readObject();
134 in.close();
135 }
136 catch (Exception e) {
137 fail(e.toString());
138 }
139 assertEquals(b1, b2);
140 }
141
142 }