1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2004, 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. * PlotRenderingInfoTests.java
  26. * ---------------------------
  27. * (C) Copyright 2004, by Object Refinery Limited and Contributors.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: PlotRenderingInfoTests.java,v 1.1 2004/08/31 14:42:21 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 20-May-2004 : Version 1 (DG);
  37. *
  38. */
  39. package org.jfree.chart.plot.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 junit.framework.Test;
  47. import junit.framework.TestCase;
  48. import junit.framework.TestSuite;
  49. import org.jfree.chart.ChartRenderingInfo;
  50. import org.jfree.chart.plot.PlotRenderingInfo;
  51. /**
  52. * Tests for the {@link PlotRenderingInfo} class.
  53. */
  54. public class PlotRenderingInfoTests extends TestCase {
  55. /**
  56. * Returns the tests as a test suite.
  57. *
  58. * @return The test suite.
  59. */
  60. public static Test suite() {
  61. return new TestSuite(PlotRenderingInfoTests.class);
  62. }
  63. /**
  64. * Constructs a new set of tests.
  65. *
  66. * @param name the name of the tests.
  67. */
  68. public PlotRenderingInfoTests(String name) {
  69. super(name);
  70. }
  71. /**
  72. * Test the equals() method.
  73. */
  74. public void testEquals() {
  75. PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo());
  76. PlotRenderingInfo p2 = new PlotRenderingInfo(new ChartRenderingInfo());
  77. assertTrue(p1.equals(p2));
  78. assertTrue(p2.equals(p1));
  79. }
  80. /**
  81. * Confirm that cloning works.
  82. */
  83. public void testCloning() {
  84. PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo());
  85. PlotRenderingInfo p2 = null;
  86. try {
  87. p2 = (PlotRenderingInfo) p1.clone();
  88. }
  89. catch (CloneNotSupportedException e) {
  90. e.printStackTrace();
  91. System.err.println("PiePlotTests.testCloning: failed to clone.");
  92. }
  93. assertTrue(p1 != p2);
  94. assertTrue(p1.getClass() == p2.getClass());
  95. assertTrue(p1.equals(p2));
  96. }
  97. /**
  98. * Serialize an instance, restore it, and check for equality.
  99. */
  100. public void testSerialization() {
  101. PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo());
  102. PlotRenderingInfo p2 = null;
  103. try {
  104. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  105. ObjectOutput out = new ObjectOutputStream(buffer);
  106. out.writeObject(p1);
  107. out.close();
  108. ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
  109. p2 = (PlotRenderingInfo) in.readObject();
  110. in.close();
  111. }
  112. catch (Exception e) {
  113. System.out.println(e.toString());
  114. }
  115. assertEquals(p1, p2);
  116. }
  117. }