ArcDialFrameTest.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. * ArcDialFrameTest.java
  29. * ---------------------
  30. * (C) Copyright 2006-2013, by Object Refinery Limited and Contributors.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * Changes
  36. * -------
  37. * 03-Nov-2006 : Version 1 (DG);
  38. * 24-Oct-2007 : Renamed (DG);
  39. *
  40. */
  41. package org.jfree.chart.plot.dial;
  42. import static org.junit.Assert.assertEquals;
  43. import static org.junit.Assert.assertFalse;
  44. import static org.junit.Assert.assertTrue;
  45. import java.awt.BasicStroke;
  46. import java.awt.Color;
  47. import java.awt.GradientPaint;
  48. import org.jfree.chart.TestUtilities;
  49. import org.junit.Test;
  50. /**
  51. * Tests for the {@link ArcDialFrame} class.
  52. */
  53. public class ArcDialFrameTest {
  54. /**
  55. * Confirm that the equals method can distinguish all the required fields.
  56. */
  57. @Test
  58. public void testEquals() {
  59. ArcDialFrame f1 = new ArcDialFrame();
  60. ArcDialFrame f2 = new ArcDialFrame();
  61. assertTrue(f1.equals(f2));
  62. // background paint
  63. f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
  64. 3.0f, 4.0f, Color.yellow));
  65. assertFalse(f1.equals(f2));
  66. f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
  67. 3.0f, 4.0f, Color.yellow));
  68. assertTrue(f1.equals(f2));
  69. // foreground paint
  70. f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
  71. 3.0f, 4.0f, Color.yellow));
  72. assertFalse(f1.equals(f2));
  73. f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
  74. 3.0f, 4.0f, Color.yellow));
  75. assertTrue(f1.equals(f2));
  76. // stroke
  77. f1.setStroke(new BasicStroke(1.1f));
  78. assertFalse(f1.equals(f2));
  79. f2.setStroke(new BasicStroke(1.1f));
  80. assertTrue(f1.equals(f2));
  81. // inner radius
  82. f1.setInnerRadius(0.11);
  83. assertFalse(f1.equals(f2));
  84. f2.setInnerRadius(0.11);
  85. assertTrue(f1.equals(f2));
  86. // outer radius
  87. f1.setOuterRadius(0.88);
  88. assertFalse(f1.equals(f2));
  89. f2.setOuterRadius(0.88);
  90. assertTrue(f1.equals(f2));
  91. // startAngle
  92. f1.setStartAngle(99);
  93. assertFalse(f1.equals(f2));
  94. f2.setStartAngle(99);
  95. assertTrue(f1.equals(f2));
  96. // extent
  97. f1.setExtent(33);
  98. assertFalse(f1.equals(f2));
  99. f2.setExtent(33);
  100. assertTrue(f1.equals(f2));
  101. // check an inherited attribute
  102. f1.setVisible(false);
  103. assertFalse(f1.equals(f2));
  104. f2.setVisible(false);
  105. assertTrue(f1.equals(f2));
  106. }
  107. /**
  108. * Two objects that are equal are required to return the same hashCode.
  109. */
  110. @Test
  111. public void testHashCode() {
  112. ArcDialFrame f1 = new ArcDialFrame();
  113. ArcDialFrame f2 = new ArcDialFrame();
  114. assertTrue(f1.equals(f2));
  115. int h1 = f1.hashCode();
  116. int h2 = f2.hashCode();
  117. assertEquals(h1, h2);
  118. }
  119. /**
  120. * Confirm that cloning works.
  121. */
  122. @Test
  123. public void testCloning() throws CloneNotSupportedException {
  124. ArcDialFrame f1 = new ArcDialFrame();
  125. ArcDialFrame f2 = (ArcDialFrame) f1.clone();
  126. assertTrue(f1 != f2);
  127. assertTrue(f1.getClass() == f2.getClass());
  128. assertTrue(f1.equals(f2));
  129. // check that the listener lists are independent
  130. MyDialLayerChangeListener l1 = new MyDialLayerChangeListener();
  131. f1.addChangeListener(l1);
  132. assertTrue(f1.hasListener(l1));
  133. assertFalse(f2.hasListener(l1));
  134. }
  135. /**
  136. * Serialize an instance, restore it, and check for equality.
  137. */
  138. @Test
  139. public void testSerialization() {
  140. ArcDialFrame f1 = new ArcDialFrame();
  141. ArcDialFrame f2 = (ArcDialFrame) TestUtilities.serialised(f1);
  142. assertEquals(f1, f2);
  143. }
  144. }