001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * --------------------
028: * LineBorderTests.java
029: * --------------------
030: * (C) Copyright 2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: LineBorderTests.java,v 1.1.2.1 2007/03/16 15:26:16 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 16-Mar-2007 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.chart.block.junit;
044:
045: import java.awt.BasicStroke;
046: import java.awt.Color;
047: import java.awt.GradientPaint;
048: import java.io.ByteArrayInputStream;
049: import java.io.ByteArrayOutputStream;
050: import java.io.ObjectInput;
051: import java.io.ObjectInputStream;
052: import java.io.ObjectOutput;
053: import java.io.ObjectOutputStream;
054:
055: import junit.framework.Test;
056: import junit.framework.TestCase;
057: import junit.framework.TestSuite;
058:
059: import org.jfree.chart.block.LineBorder;
060: import org.jfree.ui.RectangleInsets;
061:
062: /**
063: * Tests for the {@link LineBorder} class.
064: */
065: public class LineBorderTests extends TestCase {
066:
067: /**
068: * Returns the tests as a test suite.
069: *
070: * @return The test suite.
071: */
072: public static Test suite() {
073: return new TestSuite(LineBorderTests.class);
074: }
075:
076: /**
077: * Constructs a new set of tests.
078: *
079: * @param name the name of the tests.
080: */
081: public LineBorderTests(String name) {
082: super (name);
083: }
084:
085: /**
086: * Confirm that the equals() method can distinguish all the required fields.
087: */
088: public void testEquals() {
089: LineBorder b1 = new LineBorder(Color.red,
090: new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0,
091: 1.0, 1.0));
092: LineBorder b2 = new LineBorder(Color.red,
093: new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0,
094: 1.0, 1.0));
095: assertTrue(b1.equals(b2));
096: assertTrue(b2.equals(b2));
097:
098: b1 = new LineBorder(Color.blue, new BasicStroke(1.0f),
099: new RectangleInsets(1.0, 1.0, 1.0, 1.0));
100: assertFalse(b1.equals(b2));
101: b2 = new LineBorder(Color.blue, new BasicStroke(1.0f),
102: new RectangleInsets(1.0, 1.0, 1.0, 1.0));
103: assertTrue(b1.equals(b2));
104:
105: b1 = new LineBorder(Color.blue, new BasicStroke(1.1f),
106: new RectangleInsets(1.0, 1.0, 1.0, 1.0));
107: assertFalse(b1.equals(b2));
108: b2 = new LineBorder(Color.blue, new BasicStroke(1.1f),
109: new RectangleInsets(1.0, 1.0, 1.0, 1.0));
110: assertTrue(b1.equals(b2));
111:
112: b1 = new LineBorder(Color.blue, new BasicStroke(1.1f),
113: new RectangleInsets(1.0, 2.0, 3.0, 4.0));
114: assertFalse(b1.equals(b2));
115: b2 = new LineBorder(Color.blue, new BasicStroke(1.1f),
116: new RectangleInsets(1.0, 2.0, 3.0, 4.0));
117: assertTrue(b1.equals(b2));
118:
119: }
120:
121: /**
122: * Immutable - cloning not necessary.
123: */
124: public void testCloning() {
125: LineBorder b1 = new LineBorder();
126: assertFalse(b1 instanceof Cloneable);
127: }
128:
129: /**
130: * Serialize an instance, restore it, and check for equality.
131: */
132: public void testSerialization() {
133: LineBorder b1 = new LineBorder(new GradientPaint(1.0f, 2.0f,
134: Color.red, 3.0f, 4.0f, Color.yellow), new BasicStroke(
135: 1.0f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
136: LineBorder b2 = null;
137: try {
138: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
139: ObjectOutput out = new ObjectOutputStream(buffer);
140: out.writeObject(b1);
141: out.close();
142:
143: ObjectInput in = new ObjectInputStream(
144: new ByteArrayInputStream(buffer.toByteArray()));
145: b2 = (LineBorder) in.readObject();
146: in.close();
147: } catch (Exception e) {
148: fail(e.toString());
149: }
150: assertTrue(b1.equals(b2));
151: }
152:
153: }
|