CyclicNumberAxisTest.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. * CyclicAxisTest.java
  29. * -------------------
  30. * (C) Copyright 2003-2013, by Object Refinery Limited and Contributors.
  31. *
  32. * Original Author: Nicolas Brodu
  33. * Contributor(s): -;
  34. *
  35. * Changes
  36. * -------
  37. * 19-Nov-2003 : First version (NB);
  38. * 05-Oct-2004 : Removed extension of NumberAxisTests (DG);
  39. * 07-Jan-2004 : Added test for hashCode() (DG);
  40. * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
  41. *
  42. */
  43. package org.jfree.chart.axis;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertTrue;
  47. import java.awt.BasicStroke;
  48. import java.awt.Color;
  49. import java.awt.GradientPaint;
  50. import java.awt.Stroke;
  51. import org.jfree.chart.TestUtilities;
  52. import org.junit.Test;
  53. /**
  54. * Tests for the {@link CyclicNumberAxis} class.
  55. */
  56. public class CyclicNumberAxisTest {
  57. /**
  58. * Confirm that cloning works.
  59. */
  60. @Test
  61. public void testCloning() throws CloneNotSupportedException {
  62. CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test");
  63. CyclicNumberAxis a2 = (CyclicNumberAxis) a1.clone();
  64. assertTrue(a1 != a2);
  65. assertTrue(a1.getClass() == a2.getClass());
  66. assertTrue(a1.equals(a2));
  67. }
  68. /**
  69. * Confirm that the equals method can distinguish all the required fields.
  70. */
  71. @Test
  72. public void testEquals() {
  73. CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test");
  74. CyclicNumberAxis a2 = new CyclicNumberAxis(10, 0, "Test");
  75. assertTrue(a1.equals(a2));
  76. // period
  77. a1.setPeriod(5);
  78. assertFalse(a1.equals(a2));
  79. a2.setPeriod(5);
  80. assertTrue(a1.equals(a2));
  81. // offset
  82. a1.setOffset(2.0);
  83. assertFalse(a1.equals(a2));
  84. a2.setOffset(2.0);
  85. assertTrue(a1.equals(a2));
  86. // advance line Paint
  87. a1.setAdvanceLinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
  88. 3.0f, 4.0f, Color.black));
  89. assertFalse(a1.equals(a2));
  90. a2.setAdvanceLinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
  91. 3.0f, 4.0f, Color.black));
  92. assertTrue(a1.equals(a2));
  93. // advance line Stroke
  94. Stroke stroke = new BasicStroke(0.2f);
  95. a1.setAdvanceLineStroke(stroke);
  96. assertFalse(a1.equals(a2));
  97. a2.setAdvanceLineStroke(stroke);
  98. assertTrue(a1.equals(a2));
  99. // advance line Visible
  100. a1.setAdvanceLineVisible(!a1.isAdvanceLineVisible());
  101. assertFalse(a1.equals(a2));
  102. a2.setAdvanceLineVisible(a1.isAdvanceLineVisible());
  103. assertTrue(a1.equals(a2));
  104. // cycle bound mapping
  105. a1.setBoundMappedToLastCycle(!a1.isBoundMappedToLastCycle());
  106. assertFalse(a1.equals(a2));
  107. a2.setBoundMappedToLastCycle(a1.isBoundMappedToLastCycle());
  108. assertTrue(a1.equals(a2));
  109. }
  110. /**
  111. * Two objects that are equal are required to return the same hashCode.
  112. */
  113. @Test
  114. public void testHashCode() {
  115. CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test");
  116. CyclicNumberAxis a2 = new CyclicNumberAxis(10, 0, "Test");
  117. assertTrue(a1.equals(a2));
  118. int h1 = a1.hashCode();
  119. int h2 = a2.hashCode();
  120. assertEquals(h1, h2);
  121. }
  122. /**
  123. * Serialize an instance, restore it, and check for equality.
  124. */
  125. @Test
  126. public void testSerialization() {
  127. CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test Axis");
  128. CyclicNumberAxis a2 = (CyclicNumberAxis) TestUtilities.serialised(a1);
  129. assertEquals(a1, a2);
  130. }
  131. }