/
StackedAreaRendererTests.java
189 lines (163 loc) · 5.79 KB
/
StackedAreaRendererTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2011, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.]
*
* -----------------------------
* StackedAreaRendererTests.java
* -----------------------------
* (C) Copyright 2003-2009, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* Changes
* -------
* 25-Mar-2003 : Version 1 (DG);
* 23-Apr-2008 : Added testPublicCloneable() (DG);
* 04-Feb-2009 : Added testFindRangeBounds (DG);
*
*/
package org.jfree.chart.renderer.category.junit;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jfree.chart.renderer.category.StackedAreaRenderer;
import org.jfree.data.Range;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.util.PublicCloneable;
/**
* Tests for the {@link StackedAreaRendererTests} class.
*/
public class StackedAreaRendererTests extends TestCase {
/**
* Returns the tests as a test suite.
*
* @return The test suite.
*/
public static Test suite() {
return new TestSuite(StackedAreaRendererTests.class);
}
/**
* Constructs a new set of tests.
*
* @param name the name of the tests.
*/
public StackedAreaRendererTests(String name) {
super(name);
}
/**
* Some checks for the findRangeBounds() method.
*/
public void testFindRangeBounds() {
StackedAreaRenderer r = new StackedAreaRenderer();
assertNull(r.findRangeBounds(null));
// an empty dataset should return a null range
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
assertNull(r.findRangeBounds(dataset));
dataset.addValue(1.0, "R1", "C1");
assertEquals(new Range(0.0, 1.0), r.findRangeBounds(dataset));
dataset.addValue(-2.0, "R1", "C2");
assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));
dataset.addValue(null, "R1", "C3");
assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));
dataset.addValue(2.0, "R2", "C1");
assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset));
dataset.addValue(null, "R2", "C2");
assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset));
}
/**
* Check that the equals() method distinguishes all fields.
*/
public void testEquals() {
StackedAreaRenderer r1 = new StackedAreaRenderer();
StackedAreaRenderer r2 = new StackedAreaRenderer();
assertEquals(r1, r2);
r1.setRenderAsPercentages(true);
assertFalse(r1.equals(r2));
r2.setRenderAsPercentages(true);
assertTrue(r1.equals(r2));
}
/**
* Two objects that are equal are required to return the same hashCode.
*/
public void testHashcode() {
StackedAreaRenderer r1 = new StackedAreaRenderer();
StackedAreaRenderer r2 = new StackedAreaRenderer();
assertTrue(r1.equals(r2));
int h1 = r1.hashCode();
int h2 = r2.hashCode();
assertEquals(h1, h2);
}
/**
* Confirm that cloning works.
*/
public void testCloning() {
StackedAreaRenderer r1 = new StackedAreaRenderer();
StackedAreaRenderer r2 = null;
try {
r2 = (StackedAreaRenderer) r1.clone();
}
catch (CloneNotSupportedException e) {
e.printStackTrace();
}
assertTrue(r1 != r2);
assertTrue(r1.getClass() == r2.getClass());
assertTrue(r1.equals(r2));
}
/**
* Check that this class implements PublicCloneable.
*/
public void testPublicCloneable() {
StackedAreaRenderer r1 = new StackedAreaRenderer();
assertTrue(r1 instanceof PublicCloneable);
}
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization() {
StackedAreaRenderer r1 = new StackedAreaRenderer();
StackedAreaRenderer r2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(r1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray()));
r2 = (StackedAreaRenderer) in.readObject();
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertEquals(r1, r2);
}
}