1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
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.
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.
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,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
30
* (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
32
* Original Author: David Gilbert (for Object Refinery Limited);
35
* $Id: PaintListTests.java,v 1.3 2005/10/18 13:25:14 mungady Exp $
39
* 13-Aug-2003 : Version 1 (DG);
40
* 27-Jun-2005 : Added test for equals() where the list contains
41
* GradientPaint instances (DG);
44
package org.jfree.util.junit;
46
import java.awt.Color;
47
import java.awt.GradientPaint;
48
import java.awt.Paint;
49
import java.io.ByteArrayInputStream;
50
import java.io.ByteArrayOutputStream;
51
import java.io.ObjectInput;
52
import java.io.ObjectInputStream;
53
import java.io.ObjectOutput;
54
import java.io.ObjectOutputStream;
56
import junit.framework.Test;
57
import junit.framework.TestCase;
58
import junit.framework.TestSuite;
60
import org.jfree.util.PaintList;
63
* Some tests for the {@link PaintList} class.
65
public class PaintListTests extends TestCase {
68
* Returns the tests as a test suite.
70
* @return The test suite.
72
public static Test suite() {
73
return new TestSuite(PaintListTests.class);
77
* Constructs a new set of tests.
79
* @param name the name of the tests.
81
public PaintListTests(final String name) {
86
* Tests the equals() method.
88
public void testEquals() {
89
final PaintList l1 = new PaintList();
90
l1.setPaint(0, Color.red);
91
l1.setPaint(1, Color.blue);
94
final PaintList l2 = new PaintList();
95
l2.setPaint(0, Color.red);
96
l2.setPaint(1, Color.blue);
99
assertTrue(l1.equals(l2));
100
assertTrue(l2.equals(l2));
104
* Tests the equals method.
106
public void testEquals2() {
107
// check two separate (but equal) colors
108
final PaintList l1 = new PaintList();
109
final Color color1 = new Color(200, 200, 200);
110
l1.setPaint(0, color1);
111
final PaintList l2 = new PaintList();
112
final Color color2 = new Color(200, 200, 200);
113
l2.setPaint(0, color2);
114
assertEquals(l1, l2);
118
* Tests the equals() method when the list contains a GradientPaint
121
public void testEquals3() {
122
// check two separate (but equal) colors
123
PaintList l1 = new PaintList();
124
Paint p1 = new GradientPaint(1.0f, 2.0f, Color.red,
125
3.0f, 4.0f, Color.blue);
127
PaintList l2 = new PaintList();
128
Paint p2 = new GradientPaint(1.0f, 2.0f, Color.red,
129
3.0f, 4.0f, Color.blue);
131
assertEquals(l1, l2);
135
* Confirm that cloning works.
137
public void testCloning() {
139
final PaintList l1 = new PaintList();
140
l1.setPaint(0, Color.red);
141
l1.setPaint(1, Color.blue);
142
l1.setPaint(2, null);
146
l2 = (PaintList) l1.clone();
148
catch (CloneNotSupportedException e) {
149
System.err.println("PaintListTests.testCloning: failed to clone.");
151
assertTrue(l1 != l2);
152
assertTrue(l1.getClass() == l2.getClass());
153
assertTrue(l1.equals(l2));
155
l2.setPaint(0, Color.green);
156
assertFalse(l1.equals(l2));
161
* Serialize an instance, restore it, and check for equality.
163
public void testSerialization() {
165
final PaintList l1 = new PaintList();
166
l1.setPaint(0, Color.red);
167
l1.setPaint(1, Color.blue);
168
l1.setPaint(2, null);
173
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
174
final ObjectOutput out = new ObjectOutputStream(buffer);
178
final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
179
l2 = (PaintList) in.readObject();
182
catch (Exception e) {
183
System.out.println(e.toString());
185
assertEquals(l1, l2);