1 /* ===========================================================
2 * JFreeChart : a free chart 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/jfreechart/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 * StackedAreaXYRendererTests.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: StackedAreaXYRendererTests.java,v 1.1 2004/08/31 14:51:19 mungady Exp $
33 *
34 * Changes
35 * -------
36 * 25-Mar-2003 : Version 1 (DG);
37 *
38 */
39
40 package org.jfree.chart.renderer.xy.junit;
41
42 import java.io.ByteArrayInputStream;
43 import java.io.ByteArrayOutputStream;
44 import java.io.ObjectInput;
45 import java.io.ObjectInputStream;
46 import java.io.ObjectOutput;
47 import java.io.ObjectOutputStream;
48
49 import junit.framework.Test;
50 import junit.framework.TestCase;
51 import junit.framework.TestSuite;
52
53 import org.jfree.chart.renderer.xy.StackedXYAreaRenderer;
54
55 /**
56 * Tests for the {@link StackedAreaXYRendererTests} class.
57 *
58 */
59 public class StackedAreaXYRendererTests extends TestCase {
60
61 /**
62 * Returns the tests as a test suite.
63 *
64 * @return the test suite.
65 */
66 public static Test suite() {
67 return new TestSuite(StackedAreaXYRendererTests.class);
68 }
69
70 /**
71 * Constructs a new set of tests.
72 *
73 * @param name the name of the tests.
74 */
75 public StackedAreaXYRendererTests(String name) {
76 super(name);
77 }
78
79 /**
80 * Problem that the equals(...) method distinguishes all fields.
81 */
82 public void testEquals() {
83 StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
84 StackedXYAreaRenderer r2 = new StackedXYAreaRenderer();
85 assertEquals(r1, r2);
86 }
87
88 /**
89 * Two objects that are equal are required to return the same hashCode.
90 */
91 public void testHashcode() {
92 StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
93 StackedXYAreaRenderer r2 = new StackedXYAreaRenderer();
94 assertTrue(r1.equals(r2));
95 int h1 = r1.hashCode();
96 int h2 = r2.hashCode();
97 assertEquals(h1, h2);
98 }
99
100 /**
101 * Confirm that cloning works.
102 */
103 public void testCloning() {
104 StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
105 StackedXYAreaRenderer r2 = null;
106 try {
107 r2 = (StackedXYAreaRenderer) r1.clone();
108 }
109 catch (CloneNotSupportedException e) {
110 System.err.println("StackedAreaXYRendererTests.testCloning: failed to clone.");
111 }
112 assertTrue(r1 != r2);
113 assertTrue(r1.getClass() == r2.getClass());
114 assertTrue(r1.equals(r2));
115
116 }
117
118 /**
119 * Serialize an instance, restore it, and check for equality.
120 */
121 public void testSerialization() {
122
123 StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
124 StackedXYAreaRenderer r2 = null;
125
126 try {
127 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
128 ObjectOutput out = new ObjectOutputStream(buffer);
129 out.writeObject(r1);
130 out.close();
131
132 ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
133 r2 = (StackedXYAreaRenderer) in.readObject();
134 in.close();
135 }
136 catch (Exception e) {
137 System.out.println(e.toString());
138 }
139 assertEquals(r1, r2);
140
141 }
142
143 }