StandardDialFrameTest.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * StandardDialFrameTest.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. * 29-Oct-2007 : Renamed StandardDialFrameTests (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 StandardDialFrame} class.
  52. */
  53. public class StandardDialFrameTest {
  54. /**
  55. * Confirm that the equals method can distinguish all the required fields.
  56. */
  57. @Test
  58. public void testEquals() {
  59. StandardDialFrame f1 = new StandardDialFrame();
  60. StandardDialFrame f2 = new StandardDialFrame();
  61. assertTrue(f1.equals(f2));
  62. // radius
  63. f1.setRadius(0.2);
  64. assertFalse(f1.equals(f2));
  65. f2.setRadius(0.2);
  66. assertTrue(f1.equals(f2));
  67. // backgroundPaint
  68. f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f,
  69. 4.0f, Color.yellow));
  70. assertFalse(f1.equals(f2));
  71. f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f,
  72. 4.0f, Color.yellow));
  73. assertTrue(f1.equals(f2));
  74. // foregroundPaint
  75. f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
  76. 4.0f, Color.green));
  77. assertFalse(f1.equals(f2));
  78. f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
  79. 4.0f, Color.green));
  80. assertTrue(f1.equals(f2));
  81. // stroke
  82. f1.setStroke(new BasicStroke(2.4f));
  83. assertFalse(f1.equals(f2));
  84. f2.setStroke(new BasicStroke(2.4f));
  85. assertTrue(f1.equals(f2));
  86. // check an inherited attribute
  87. f1.setVisible(false);
  88. assertFalse(f1.equals(f2));
  89. f2.setVisible(false);
  90. assertTrue(f1.equals(f2));
  91. }
  92. /**
  93. * Two objects that are equal are required to return the same hashCode.
  94. */
  95. @Test
  96. public void testHashCode() {
  97. StandardDialFrame f1 = new StandardDialFrame();
  98. StandardDialFrame f2 = new StandardDialFrame();
  99. assertTrue(f1.equals(f2));
  100. int h1 = f1.hashCode();
  101. int h2 = f2.hashCode();
  102. assertEquals(h1, h2);
  103. }
  104. /**
  105. * Confirm that cloning works.
  106. */
  107. @Test
  108. public void testCloning() throws CloneNotSupportedException {
  109. StandardDialFrame f1 = new StandardDialFrame();
  110. StandardDialFrame f2 = (StandardDialFrame) f1.clone();
  111. assertTrue(f1 != f2);
  112. assertTrue(f1.getClass() == f2.getClass());
  113. assertTrue(f1.equals(f2));
  114. // check that the listener lists are independent
  115. MyDialLayerChangeListener l1 = new MyDialLayerChangeListener();
  116. f1.addChangeListener(l1);
  117. assertTrue(f1.hasListener(l1));
  118. assertFalse(f2.hasListener(l1));
  119. }
  120. /**
  121. * Serialize an instance, restore it, and check for equality.
  122. */
  123. @Test
  124. public void testSerialization() {
  125. StandardDialFrame f1 = new StandardDialFrame();
  126. StandardDialFrame f2 = (StandardDialFrame) TestUtilities.serialised(f1);
  127. assertEquals(f1, f2);
  128. }
  129. }