DomainOrderTest.java 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * DomainOrderTest.java
  29. * --------------------
  30. * (C) Copyright 2005-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. * 19-May-2005 : Version 1 (DG);
  38. *
  39. */
  40. package org.jfree.data;
  41. import org.jfree.chart.TestUtilities;
  42. import org.junit.Test;
  43. import static org.junit.Assert.assertEquals;
  44. import static org.junit.Assert.assertFalse;
  45. import static org.junit.Assert.assertTrue;
  46. import static org.junit.Assert.assertSame;
  47. /**
  48. * Tests for the {@link DomainOrder} class.
  49. */
  50. public class DomainOrderTest {
  51. /**
  52. * Some checks for the equals() method.
  53. */
  54. @Test
  55. public void testEquals() {
  56. assertEquals(DomainOrder.NONE, DomainOrder.NONE);
  57. assertEquals(DomainOrder.ASCENDING, DomainOrder.ASCENDING);
  58. assertEquals(DomainOrder.DESCENDING, DomainOrder.DESCENDING);
  59. assertFalse(DomainOrder.NONE.equals(DomainOrder.ASCENDING));
  60. assertFalse(DomainOrder.NONE.equals(DomainOrder.DESCENDING));
  61. assertFalse(DomainOrder.NONE.equals(null));
  62. assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.NONE));
  63. assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.DESCENDING));
  64. assertFalse(DomainOrder.ASCENDING.equals(null));
  65. assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.NONE));
  66. assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.ASCENDING));
  67. assertFalse(DomainOrder.DESCENDING.equals(null));
  68. }
  69. /**
  70. * Two objects that are equal are required to return the same hashCode.
  71. */
  72. @Test
  73. public void testHashCode() {
  74. DomainOrder d1 = DomainOrder.ASCENDING;
  75. DomainOrder d2 = DomainOrder.ASCENDING;
  76. assertTrue(d1.equals(d2));
  77. int h1 = d1.hashCode();
  78. int h2 = d2.hashCode();
  79. assertEquals(h1, h2);
  80. }
  81. /**
  82. * Serialize an instance, restore it, and check for equality.
  83. */
  84. @Test
  85. public void testSerialization() {
  86. DomainOrder d1 = DomainOrder.ASCENDING;
  87. DomainOrder d2 = (DomainOrder) TestUtilities.serialised(d1);
  88. assertSame(d1, d2);
  89. }
  90. }