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: * DefaultBoxAndWhiskerCategoryDatasetTests.java
029: * ---------------------------------------------
030: * (C) Copyright 2004-2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: DefaultBoxAndWhiskerCategoryDatasetTests.java,v 1.1.2.2 2007/04/17 13:22:56 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 01-Mar-2004 : Version 1 (DG);
040: * 17-Apr-2007 : Added a test for bug 1701822 (DG);
041: *
042: */
043:
044: package org.jfree.data.statistics.junit;
045:
046: import java.io.ByteArrayInputStream;
047: import java.io.ByteArrayOutputStream;
048: import java.io.ObjectInput;
049: import java.io.ObjectInputStream;
050: import java.io.ObjectOutput;
051: import java.io.ObjectOutputStream;
052: import java.util.ArrayList;
053:
054: import junit.framework.Test;
055: import junit.framework.TestCase;
056: import junit.framework.TestSuite;
057:
058: import org.jfree.data.statistics.BoxAndWhiskerItem;
059: import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
060:
061: /**
062: * Tests for the {@link DefaultBoxAndWhiskerCategoryDataset} class.
063: */
064: public class DefaultBoxAndWhiskerCategoryDatasetTests extends TestCase {
065:
066: /**
067: * Returns the tests as a test suite.
068: *
069: * @return The test suite.
070: */
071: public static Test suite() {
072: return new TestSuite(
073: DefaultBoxAndWhiskerCategoryDatasetTests.class);
074: }
075:
076: /**
077: * Constructs a new set of tests.
078: *
079: * @param name the name of the tests.
080: */
081: public DefaultBoxAndWhiskerCategoryDatasetTests(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: DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
090: d1.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
091: new Double(3.0), new Double(4.0), new Double(5.0),
092: new Double(6.0), new Double(7.0), new Double(8.0),
093: new ArrayList()), "ROW1", "COLUMN1");
094: DefaultBoxAndWhiskerCategoryDataset d2 = new DefaultBoxAndWhiskerCategoryDataset();
095: d2.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
096: new Double(3.0), new Double(4.0), new Double(5.0),
097: new Double(6.0), new Double(7.0), new Double(8.0),
098: new ArrayList()), "ROW1", "COLUMN1");
099: assertTrue(d1.equals(d2));
100: assertTrue(d2.equals(d1));
101: }
102:
103: /**
104: * Serialize an instance, restore it, and check for equality.
105: */
106: public void testSerialization() {
107:
108: DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
109: d1.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
110: new Double(3.0), new Double(4.0), new Double(5.0),
111: new Double(6.0), new Double(7.0), new Double(8.0),
112: new ArrayList()), "ROW1", "COLUMN1");
113: DefaultBoxAndWhiskerCategoryDataset d2 = null;
114:
115: try {
116: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
117: ObjectOutput out = new ObjectOutputStream(buffer);
118: out.writeObject(d1);
119: out.close();
120:
121: ObjectInput in = new ObjectInputStream(
122: new ByteArrayInputStream(buffer.toByteArray()));
123: d2 = (DefaultBoxAndWhiskerCategoryDataset) in.readObject();
124: in.close();
125: } catch (Exception e) {
126: e.printStackTrace();
127: }
128: assertEquals(d1, d2);
129:
130: }
131:
132: /**
133: * Confirm that cloning works.
134: */
135: public void testCloning() {
136: DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
137: d1.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
138: new Double(3.0), new Double(4.0), new Double(5.0),
139: new Double(6.0), new Double(7.0), new Double(8.0),
140: new ArrayList()), "ROW1", "COLUMN1");
141: DefaultBoxAndWhiskerCategoryDataset d2 = null;
142: try {
143: d2 = (DefaultBoxAndWhiskerCategoryDataset) d1.clone();
144: } catch (CloneNotSupportedException e) {
145: e.printStackTrace();
146: }
147: assertTrue(d1 != d2);
148: assertTrue(d1.getClass() == d2.getClass());
149: assertTrue(d1.equals(d2));
150: }
151:
152: /**
153: * A simple test for bug report 1701822.
154: */
155: public void test1701822() {
156: DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
157: try {
158: dataset.add(new BoxAndWhiskerItem(new Double(1.0),
159: new Double(2.0), new Double(3.0), new Double(4.0),
160: new Double(5.0), new Double(6.0), null, new Double(
161: 8.0), new ArrayList()), "ROW1", "COLUMN1");
162: dataset.add(new BoxAndWhiskerItem(new Double(1.0),
163: new Double(2.0), new Double(3.0), new Double(4.0),
164: new Double(5.0), new Double(6.0), new Double(7.0),
165: null, new ArrayList()), "ROW1", "COLUMN2");
166: } catch (NullPointerException e) {
167: assertTrue(false);
168: }
169:
170: }
171: }
|