1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, 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. * DefaultBoxAndWhiskerCategoryDatasetTests.java
  26. * ---------------------------------------------
  27. * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: DefaultBoxAndWhiskerCategoryDatasetTests.java,v 1.2 2005/01/14 17:29:51 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 01-Mar-2004 : Version 1 (DG);
  37. *
  38. */
  39. package org.jfree.data.statistics.junit;
  40. import java.io.ByteArrayInputStream;
  41. import java.io.ByteArrayOutputStream;
  42. import java.io.ObjectInput;
  43. import java.io.ObjectInputStream;
  44. import java.io.ObjectOutput;
  45. import java.io.ObjectOutputStream;
  46. import java.util.ArrayList;
  47. import junit.framework.Test;
  48. import junit.framework.TestCase;
  49. import junit.framework.TestSuite;
  50. import org.jfree.data.statistics.BoxAndWhiskerItem;
  51. import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
  52. /**
  53. * Tests for the {@link DefaultBoxAndWhiskerCategoryDataset} class.
  54. */
  55. public class DefaultBoxAndWhiskerCategoryDatasetTests extends TestCase {
  56. /**
  57. * Returns the tests as a test suite.
  58. *
  59. * @return The test suite.
  60. */
  61. public static Test suite() {
  62. return new TestSuite(DefaultBoxAndWhiskerCategoryDatasetTests.class);
  63. }
  64. /**
  65. * Constructs a new set of tests.
  66. *
  67. * @param name the name of the tests.
  68. */
  69. public DefaultBoxAndWhiskerCategoryDatasetTests(String name) {
  70. super(name);
  71. }
  72. /**
  73. * Confirm that the equals method can distinguish all the required fields.
  74. */
  75. public void testEquals() {
  76. DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
  77. d1.add(
  78. new BoxAndWhiskerItem(
  79. new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0),
  80. new Double(5.0), new Double(6.0), new Double(7.0), new Double(8.0),
  81. new ArrayList()
  82. ), "ROW1", "COLUMN1"
  83. );
  84. DefaultBoxAndWhiskerCategoryDataset d2 = new DefaultBoxAndWhiskerCategoryDataset();
  85. d2.add(
  86. new BoxAndWhiskerItem(
  87. new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0),
  88. new Double(5.0), new Double(6.0), new Double(7.0), new Double(8.0),
  89. new ArrayList()
  90. ), "ROW1", "COLUMN1"
  91. );
  92. assertTrue(d1.equals(d2));
  93. assertTrue(d2.equals(d1));
  94. }
  95. /**
  96. * Serialize an instance, restore it, and check for equality.
  97. */
  98. public void testSerialization() {
  99. DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
  100. d1.add(
  101. new BoxAndWhiskerItem(
  102. new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0),
  103. new Double(5.0), new Double(6.0), new Double(7.0), new Double(8.0),
  104. new ArrayList()
  105. ), "ROW1", "COLUMN1"
  106. );
  107. DefaultBoxAndWhiskerCategoryDataset d2 = null;
  108. try {
  109. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  110. ObjectOutput out = new ObjectOutputStream(buffer);
  111. out.writeObject(d1);
  112. out.close();
  113. ObjectInput in = new ObjectInputStream(
  114. new ByteArrayInputStream(buffer.toByteArray())
  115. );
  116. d2 = (DefaultBoxAndWhiskerCategoryDataset) in.readObject();
  117. in.close();
  118. }
  119. catch (Exception e) {
  120. System.out.println(e.toString());
  121. }
  122. assertEquals(d1, d2);
  123. }
  124. }