RingPlotTest.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2014, 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. * RingPlotTest.java
  29. * -----------------
  30. * (C) Copyright 2004-2014, by Object Refinery Limited and Contributors.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * Changes
  36. * -------
  37. * 09-Nov-2004 : Version 1 (DG);
  38. * 12-Oct-2006 : Updated testEquals() (DG);
  39. * 28-Feb-2014 : Add tests for new fields (DG);
  40. *
  41. */
  42. package org.jfree.chart.plot;
  43. import static org.junit.Assert.assertEquals;
  44. import static org.junit.Assert.assertFalse;
  45. import static org.junit.Assert.assertTrue;
  46. import org.junit.Test;
  47. import java.awt.BasicStroke;
  48. import java.awt.Color;
  49. import java.awt.Font;
  50. import java.awt.GradientPaint;
  51. import java.awt.Stroke;
  52. import java.text.DecimalFormat;
  53. import org.jfree.chart.TestUtilities;
  54. /**
  55. * Tests for the {@link RingPlot} class.
  56. */
  57. public class RingPlotTest {
  58. /**
  59. * Some checks for the equals() method.
  60. */
  61. @Test
  62. public void testEquals() {
  63. RingPlot plot1 = new RingPlot(null);
  64. RingPlot plot2 = new RingPlot(null);
  65. assertTrue(plot1.equals(plot2));
  66. assertTrue(plot2.equals(plot1));
  67. plot1.setCenterTextMode(CenterTextMode.FIXED);
  68. assertFalse(plot1.equals(plot2));
  69. plot2.setCenterTextMode(CenterTextMode.FIXED);
  70. assertTrue(plot1.equals(plot2));
  71. plot1.setCenterText("ABC");
  72. assertFalse(plot1.equals(plot2));
  73. plot2.setCenterText("ABC");
  74. assertTrue(plot1.equals(plot2));
  75. plot1.setCenterTextColor(Color.RED);
  76. assertFalse(plot1.equals(plot2));
  77. plot2.setCenterTextColor(Color.RED);
  78. assertTrue(plot1.equals(plot2));
  79. plot1.setCenterTextFont(new Font(Font.SERIF, Font.PLAIN, 7));
  80. assertFalse(plot1.equals(plot2));
  81. plot2.setCenterTextFont(new Font(Font.SERIF, Font.PLAIN, 7));
  82. assertTrue(plot1.equals(plot2));
  83. plot1.setCenterTextFormatter(new DecimalFormat("0.000"));
  84. assertFalse(plot1.equals(plot2));
  85. plot2.setCenterTextFormatter(new DecimalFormat("0.000"));
  86. assertTrue(plot1.equals(plot2));
  87. // separatorsVisible
  88. plot1.setSeparatorsVisible(false);
  89. assertFalse(plot1.equals(plot2));
  90. plot2.setSeparatorsVisible(false);
  91. assertTrue(plot1.equals(plot2));
  92. // separatorStroke
  93. Stroke s = new BasicStroke(1.1f);
  94. plot1.setSeparatorStroke(s);
  95. assertFalse(plot1.equals(plot2));
  96. plot2.setSeparatorStroke(s);
  97. assertTrue(plot1.equals(plot2));
  98. // separatorPaint
  99. plot1.setSeparatorPaint(new GradientPaint(1.0f, 2.0f, Color.red,
  100. 2.0f, 1.0f, Color.blue));
  101. assertFalse(plot1.equals(plot2));
  102. plot2.setSeparatorPaint(new GradientPaint(1.0f, 2.0f, Color.red,
  103. 2.0f, 1.0f, Color.blue));
  104. assertTrue(plot1.equals(plot2));
  105. // innerSeparatorExtension
  106. plot1.setInnerSeparatorExtension(0.01);
  107. assertFalse(plot1.equals(plot2));
  108. plot2.setInnerSeparatorExtension(0.01);
  109. assertTrue(plot1.equals(plot2));
  110. // outerSeparatorExtension
  111. plot1.setOuterSeparatorExtension(0.02);
  112. assertFalse(plot1.equals(plot2));
  113. plot2.setOuterSeparatorExtension(0.02);
  114. assertTrue(plot1.equals(plot2));
  115. // sectionDepth
  116. plot1.setSectionDepth(0.12);
  117. assertFalse(plot1.equals(plot2));
  118. plot2.setSectionDepth(0.12);
  119. assertTrue(plot1.equals(plot2));
  120. }
  121. /**
  122. * Confirm that cloning works.
  123. */
  124. @Test
  125. public void testCloning() throws CloneNotSupportedException {
  126. RingPlot p1 = new RingPlot(null);
  127. GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow,
  128. 3.0f, 4.0f, Color.red);
  129. p1.setSeparatorPaint(gp);
  130. RingPlot p2 = (RingPlot) p1.clone();
  131. assertTrue(p1 != p2);
  132. assertTrue(p1.getClass() == p2.getClass());
  133. assertTrue(p1.equals(p2));
  134. }
  135. /**
  136. * Serialize an instance, restore it, and check for equality.
  137. */
  138. @Test
  139. public void testSerialization() {
  140. RingPlot p1 = new RingPlot(null);
  141. GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow,
  142. 3.0f, 4.0f, Color.red);
  143. p1.setSeparatorPaint(gp);
  144. RingPlot p2 = (RingPlot) TestUtilities.serialised(p1);
  145. assertEquals(p1, p2);
  146. }
  147. }