StandardDialRangeTest.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. * SimpleDialRangeTest.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. *
  39. */
  40. package org.jfree.chart.plot.dial;
  41. import static org.junit.Assert.assertEquals;
  42. import static org.junit.Assert.assertFalse;
  43. import static org.junit.Assert.assertTrue;
  44. import java.awt.Color;
  45. import java.awt.GradientPaint;
  46. import org.jfree.chart.TestUtilities;
  47. import org.junit.Test;
  48. /**
  49. * Tests for the {@link StandardDialRange} class.
  50. */
  51. public class StandardDialRangeTest {
  52. /**
  53. * Confirm that the equals method can distinguish all the required fields.
  54. */
  55. @Test
  56. public void testEquals() {
  57. StandardDialRange r1 = new StandardDialRange();
  58. StandardDialRange r2 = new StandardDialRange();
  59. assertTrue(r1.equals(r2));
  60. // lowerBound
  61. r1.setLowerBound(1.1);
  62. assertFalse(r1.equals(r2));
  63. r2.setLowerBound(1.1);
  64. assertTrue(r1.equals(r2));
  65. // upperBound
  66. r1.setUpperBound(11.1);
  67. assertFalse(r1.equals(r2));
  68. r2.setUpperBound(11.1);
  69. assertTrue(r1.equals(r2));
  70. // paint
  71. r1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
  72. Color.blue));
  73. assertFalse(r1.equals(r2));
  74. r2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
  75. Color.blue));
  76. assertTrue(r1.equals(r2));
  77. // check an inherited attribute
  78. r1.setVisible(false);
  79. assertFalse(r1.equals(r2));
  80. r2.setVisible(false);
  81. assertTrue(r1.equals(r2));
  82. }
  83. /**
  84. * Two objects that are equal are required to return the same hashCode.
  85. */
  86. @Test
  87. public void testHashCode() {
  88. StandardDialRange r1 = new StandardDialRange();
  89. StandardDialRange r2 = new StandardDialRange();
  90. assertTrue(r1.equals(r2));
  91. int h1 = r1.hashCode();
  92. int h2 = r2.hashCode();
  93. assertEquals(h1, h2);
  94. }
  95. /**
  96. * Confirm that cloning works.
  97. */
  98. @Test
  99. public void testCloning() throws CloneNotSupportedException {
  100. StandardDialRange r1 = new StandardDialRange();
  101. StandardDialRange r2 = (StandardDialRange) r1.clone();
  102. assertTrue(r1 != r2);
  103. assertTrue(r1.getClass() == r2.getClass());
  104. assertTrue(r1.equals(r2));
  105. // check that the listener lists are independent
  106. MyDialLayerChangeListener l1 = new MyDialLayerChangeListener();
  107. r1.addChangeListener(l1);
  108. assertTrue(r1.hasListener(l1));
  109. assertFalse(r2.hasListener(l1));
  110. }
  111. /**
  112. * Serialize an instance, restore it, and check for equality.
  113. */
  114. @Test
  115. public void testSerialization() {
  116. StandardDialRange r1 = new StandardDialRange();
  117. StandardDialRange r2 = (StandardDialRange) TestUtilities.serialised(r1);
  118. assertEquals(r1, r2);
  119. }
  120. }