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. * IntervalMarkerTests.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: IntervalMarkerTests.java,v 1.1 2004/08/31 14:42:21 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 14-Jun-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.plot.IntervalMarker;
  50. import org.jfree.ui.GradientPaintTransformType;
  51. import org.jfree.ui.GradientPaintTransformer;
  52. import org.jfree.ui.StandardGradientPaintTransformer;
  53. /**
  54. * Tests for the {@link IntervalMarker} class.
  55. */
  56. public class IntervalMarkerTests 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(IntervalMarkerTests.class);
  64. }
  65. /**
  66. * Constructs a new set of tests.
  67. *
  68. * @param name the name of the tests.
  69. */
  70. public IntervalMarkerTests(String name) {
  71. super(name);
  72. }
  73. /**
  74. * Confirm that the equals method can distinguish all the required fields.
  75. */
  76. public void testEquals() {
  77. IntervalMarker m1 = new IntervalMarker(45.0, 50.0);
  78. IntervalMarker m2 = new IntervalMarker(45.0, 50.0);
  79. assertTrue(m1.equals(m2));
  80. assertTrue(m2.equals(m1));
  81. m1 = new IntervalMarker(44.0, 50.0);
  82. assertFalse(m1.equals(m2));
  83. m2 = new IntervalMarker(44.0, 50.0);
  84. assertTrue(m1.equals(m2));
  85. m1 = new IntervalMarker(44.0, 55.0);
  86. assertFalse(m1.equals(m2));
  87. m2 = new IntervalMarker(44.0, 55.0);
  88. assertTrue(m1.equals(m2));
  89. GradientPaintTransformer t = new StandardGradientPaintTransformer(
  90. GradientPaintTransformType.HORIZONTAL
  91. );
  92. m1.setGradientPaintTransformer(t);
  93. assertFalse(m1.equals(m2));
  94. m2.setGradientPaintTransformer(t);
  95. assertTrue(m1.equals(m2));
  96. }
  97. /**
  98. * Confirm that cloning works.
  99. */
  100. public void testCloning() {
  101. IntervalMarker m1 = new IntervalMarker(45.0, 50.0);
  102. IntervalMarker m2 = null;
  103. try {
  104. m2 = (IntervalMarker) m1.clone();
  105. }
  106. catch (CloneNotSupportedException e) {
  107. System.err.println("Failed to clone.");
  108. }
  109. assertTrue(m1 != m2);
  110. assertTrue(m1.getClass() == m2.getClass());
  111. assertTrue(m1.equals(m2));
  112. }
  113. /**
  114. * Serialize an instance, restore it, and check for equality.
  115. */
  116. public void testSerialization() {
  117. IntervalMarker m1 = new IntervalMarker(45.0, 50.0);
  118. IntervalMarker m2 = null;
  119. try {
  120. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  121. ObjectOutput out = new ObjectOutputStream(buffer);
  122. out.writeObject(m1);
  123. out.close();
  124. ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
  125. m2 = (IntervalMarker) in.readObject();
  126. in.close();
  127. }
  128. catch (Exception e) {
  129. System.out.println(e.toString());
  130. }
  131. boolean b = m1.equals(m2);
  132. assertTrue(b);
  133. }
  134. }