AxisSpaceTest.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * AxisSpaceTest.java
  29. * ------------------
  30. * (C) Copyright 2003-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. * 14-Aug-2003 : Version 1 (DG);
  38. * 07-Jan-2005 : Added hashCode test (DG);
  39. *
  40. */
  41. package org.jfree.chart.axis;
  42. import static org.junit.Assert.assertEquals;
  43. import static org.junit.Assert.assertTrue;
  44. import static org.junit.Assert.assertFalse;
  45. import org.junit.Test;
  46. /**
  47. * Tests for the {@link AxisSpace} class.
  48. */
  49. public class AxisSpaceTest {
  50. /**
  51. * Check that the equals() method can distinguish all fields.
  52. */
  53. @Test
  54. public void testEquals() {
  55. AxisSpace a1 = new AxisSpace();
  56. AxisSpace a2 = new AxisSpace();
  57. assertEquals(a1, a2);
  58. a1.setTop(1.11);
  59. assertFalse(a1.equals(a2));
  60. a2.setTop(1.11);
  61. assertTrue(a1.equals(a2));
  62. a1.setBottom(2.22);
  63. assertFalse(a1.equals(a2));
  64. a2.setBottom(2.22);
  65. assertTrue(a1.equals(a2));
  66. a1.setLeft(3.33);
  67. assertFalse(a1.equals(a2));
  68. a2.setLeft(3.33);
  69. assertTrue(a1.equals(a2));
  70. a1.setRight(4.44);
  71. assertFalse(a1.equals(a2));
  72. a2.setRight(4.44);
  73. assertTrue(a1.equals(a2));
  74. }
  75. /**
  76. * Two objects that are equal are required to return the same hashCode.
  77. */
  78. @Test
  79. public void testHashCode() {
  80. AxisSpace s1 = new AxisSpace();
  81. AxisSpace s2 = new AxisSpace();
  82. assertTrue(s1.equals(s2));
  83. int h1 = s1.hashCode();
  84. int h2 = s2.hashCode();
  85. assertEquals(h1, h2);
  86. }
  87. /**
  88. * Confirm that cloning works.
  89. */
  90. @Test
  91. public void testCloning() throws CloneNotSupportedException {
  92. AxisSpace s1 = new AxisSpace();
  93. AxisSpace s2 = (AxisSpace) s1.clone();
  94. assertTrue(s1 != s2);
  95. assertTrue(s1.getClass() == s2.getClass());
  96. assertTrue(s1.equals(s2));
  97. }
  98. }