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. * DonutPlotTests.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: RingPlotTests.java,v 1.1 2005/02/22 12:55:35 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 9-Nov-2004 : Version 1 (DG);
  37. *
  38. */
  39. package org.jfree.chart.plot.junit;
  40. import java.awt.BasicStroke;
  41. import java.awt.Color;
  42. import java.awt.Stroke;
  43. import java.io.ByteArrayInputStream;
  44. import java.io.ByteArrayOutputStream;
  45. import java.io.ObjectInput;
  46. import java.io.ObjectInputStream;
  47. import java.io.ObjectOutput;
  48. import java.io.ObjectOutputStream;
  49. import junit.framework.Test;
  50. import junit.framework.TestCase;
  51. import junit.framework.TestSuite;
  52. import org.jfree.chart.plot.RingPlot;
  53. /**
  54. * Tests for the {@link RingPlot} class.
  55. */
  56. public class RingPlotTests extends TestCase {
  57. /**
  58. * Returns the tests as a test suite.
  59. *
  60. * @return The test suite.
  61. */
  62. public static Test suite() {
  63. return new TestSuite(RingPlotTests.class);
  64. }
  65. /**
  66. * Constructs a new set of tests.
  67. *
  68. * @param name the name of the tests.
  69. */
  70. public RingPlotTests(String name) {
  71. super(name);
  72. }
  73. /**
  74. * Some checks for the equals() method.
  75. */
  76. public void testEquals() {
  77. RingPlot plot1 = new RingPlot(null);
  78. RingPlot plot2 = new RingPlot(null);
  79. assertTrue(plot1.equals(plot2));
  80. assertTrue(plot2.equals(plot1));
  81. // separatorsVisible
  82. plot1.setSeparatorsVisible(false);
  83. assertFalse(plot1.equals(plot2));
  84. plot2.setSeparatorsVisible(false);
  85. assertTrue(plot1.equals(plot2));
  86. // separatorStroke
  87. Stroke s = new BasicStroke(1.1f);
  88. plot1.setSeparatorStroke(s);
  89. assertFalse(plot1.equals(plot2));
  90. plot2.setSeparatorStroke(s);
  91. assertTrue(plot1.equals(plot2));
  92. // separatorPaint
  93. plot1.setSeparatorPaint(Color.red);
  94. assertFalse(plot1.equals(plot2));
  95. plot2.setSeparatorPaint(Color.red);
  96. assertTrue(plot1.equals(plot2));
  97. // innerSeparatorExtension
  98. plot1.setInnerSeparatorExtension(0.01);
  99. assertFalse(plot1.equals(plot2));
  100. plot2.setInnerSeparatorExtension(0.01);
  101. assertTrue(plot1.equals(plot2));
  102. // outerSeparatorExtension
  103. plot1.setOuterSeparatorExtension(0.02);
  104. assertFalse(plot1.equals(plot2));
  105. plot2.setOuterSeparatorExtension(0.02);
  106. assertTrue(plot1.equals(plot2));
  107. }
  108. /**
  109. * Confirm that cloning works.
  110. */
  111. public void testCloning() {
  112. RingPlot p1 = new RingPlot(null);
  113. RingPlot p2 = null;
  114. try {
  115. p2 = (RingPlot) p1.clone();
  116. }
  117. catch (CloneNotSupportedException e) {
  118. e.printStackTrace();
  119. System.err.println("Failed to clone.");
  120. }
  121. assertTrue(p1 != p2);
  122. assertTrue(p1.getClass() == p2.getClass());
  123. assertTrue(p1.equals(p2));
  124. }
  125. /**
  126. * Serialize an instance, restore it, and check for equality.
  127. */
  128. public void testSerialization() {
  129. RingPlot p1 = new RingPlot(null);
  130. RingPlot p2 = null;
  131. try {
  132. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  133. ObjectOutput out = new ObjectOutputStream(buffer);
  134. out.writeObject(p1);
  135. out.close();
  136. ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
  137. p2 = (RingPlot) in.readObject();
  138. in.close();
  139. }
  140. catch (Exception e) {
  141. System.out.println(e.toString());
  142. }
  143. assertEquals(p1, p2);
  144. }
  145. }