XYStepAreaRendererTest.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2013, 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
  10. * under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  17. * License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  22. * USA.
  23. *
  24. * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  25. * Other names may be trademarks of their respective owners.]
  26. *
  27. * ---------------------------
  28. * XYStepAreaRendererTest.java
  29. * ---------------------------
  30. * (C) Copyright 2003-2013, by Object Refinery Limited and Contributors.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): Matthias Rose;
  34. *
  35. * Changes
  36. * -------
  37. * 25-Mar-2003 : Version 1 (DG);
  38. * 26-Sep-2003 : copied XYStepRendererTests.java and used for
  39. * testing XYStepAreaRenderer (MR);
  40. * 14-Feb-2007 : Extended testEquals() (DG);
  41. * 22-Apr-2008 : Added testPublicCloneable (DG);
  42. * 05-Dec-2013 : Add stepPoint to equals() test (DG);
  43. *
  44. */
  45. package org.jfree.chart.renderer.xy;
  46. import static org.junit.Assert.assertEquals;
  47. import static org.junit.Assert.assertTrue;
  48. import static org.junit.Assert.assertFalse;
  49. import static org.junit.Assert.fail;
  50. import org.jfree.chart.JFreeChart;
  51. import org.jfree.chart.TestUtilities;
  52. import org.jfree.chart.axis.NumberAxis;
  53. import org.jfree.chart.plot.XYPlot;
  54. import org.jfree.data.xy.DefaultTableXYDataset;
  55. import org.jfree.data.xy.XYSeries;
  56. import org.jfree.util.PublicCloneable;
  57. import org.junit.Test;
  58. /**
  59. * Tests for the {@link XYStepAreaRenderer} class.
  60. */
  61. public class XYStepAreaRendererTest {
  62. /**
  63. * Check that the equals() method distinguishes all fields.
  64. */
  65. @Test
  66. public void testEquals() {
  67. XYStepAreaRenderer r1 = new XYStepAreaRenderer();
  68. XYStepAreaRenderer r2 = new XYStepAreaRenderer();
  69. assertEquals(r1, r2);
  70. r1.setOutline(true);
  71. assertFalse(r1.equals(r2));
  72. r2.setOutline(true);
  73. assertTrue(r1.equals(r2));
  74. r1.setShapesVisible(true);
  75. assertFalse(r1.equals(r2));
  76. r2.setShapesVisible(true);
  77. assertTrue(r1.equals(r2));
  78. r1.setShapesFilled(true);
  79. assertFalse(r1.equals(r2));
  80. r2.setShapesFilled(true);
  81. assertTrue(r1.equals(r2));
  82. r1.setPlotArea(false);
  83. assertFalse(r1.equals(r2));
  84. r2.setPlotArea(false);
  85. assertTrue(r1.equals(r2));
  86. r1.setRangeBase(-1.0);
  87. assertFalse(r1.equals(r2));
  88. r2.setRangeBase(-1.0);
  89. assertTrue(r1.equals(r2));
  90. r1.setStepPoint(0.33);
  91. assertFalse(r1.equals(r2));
  92. r2.setStepPoint(0.33);
  93. assertTrue(r1.equals(r2));
  94. }
  95. /**
  96. * Two objects that are equal are required to return the same hashCode.
  97. */
  98. @Test
  99. public void testHashcode() {
  100. XYStepAreaRenderer r1 = new XYStepAreaRenderer();
  101. XYStepAreaRenderer r2 = new XYStepAreaRenderer();
  102. assertTrue(r1.equals(r2));
  103. int h1 = r1.hashCode();
  104. int h2 = r2.hashCode();
  105. assertEquals(h1, h2);
  106. }
  107. /**
  108. * Confirm that cloning works.
  109. */
  110. @Test
  111. public void testCloning() throws CloneNotSupportedException {
  112. XYStepAreaRenderer r1 = new XYStepAreaRenderer();
  113. XYStepAreaRenderer r2 = (XYStepAreaRenderer) r1.clone();
  114. assertTrue(r1 != r2);
  115. assertTrue(r1.getClass() == r2.getClass());
  116. assertTrue(r1.equals(r2));
  117. }
  118. /**
  119. * Verify that this class implements {@link PublicCloneable}.
  120. */
  121. @Test
  122. public void testPublicCloneable() {
  123. XYStepAreaRenderer r1 = new XYStepAreaRenderer();
  124. assertTrue(r1 instanceof PublicCloneable);
  125. }
  126. /**
  127. * Serialize an instance, restore it, and check for equality.
  128. */
  129. @Test
  130. public void testSerialization() {
  131. XYStepAreaRenderer r1 = new XYStepAreaRenderer();
  132. XYStepAreaRenderer r2 = (XYStepAreaRenderer)
  133. TestUtilities.serialised(r1);
  134. assertEquals(r1, r2);
  135. }
  136. /**
  137. * Draws the chart with a <code>null</code> info object to make sure that
  138. * no exceptions are thrown (particularly by code in the renderer).
  139. */
  140. @Test
  141. public void testDrawWithNullInfo() {
  142. try {
  143. DefaultTableXYDataset dataset = new DefaultTableXYDataset();
  144. XYSeries s1 = new XYSeries("Series 1", true, false);
  145. s1.add(5.0, 5.0);
  146. s1.add(10.0, 15.5);
  147. s1.add(15.0, 9.5);
  148. s1.add(20.0, 7.5);
  149. dataset.addSeries(s1);
  150. XYSeries s2 = new XYSeries("Series 2", true, false);
  151. s2.add(5.0, 5.0);
  152. s2.add(10.0, 15.5);
  153. s2.add(15.0, 9.5);
  154. s2.add(20.0, 3.5);
  155. dataset.addSeries(s2);
  156. XYPlot plot = new XYPlot(dataset,
  157. new NumberAxis("X"), new NumberAxis("Y"),
  158. new XYStepAreaRenderer());
  159. JFreeChart chart = new JFreeChart(plot);
  160. /* BufferedImage image = */ chart.createBufferedImage(300, 200,
  161. null);
  162. }
  163. catch (NullPointerException e) {
  164. fail("No exception should be thrown.");
  165. }
  166. }
  167. }