1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, 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 under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ------------------------------
  25. * DateTickMarkPositionTests.java
  26. * ------------------------------
  27. * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: DateTickMarkPositionTests.java,v 1.2 2005/01/07 16:37:58 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 19-May-2004 : Version 1 (DG);
  37. *
  38. */
  39. package org.jfree.chart.axis.junit;
  40. import java.io.ByteArrayInputStream;
  41. import java.io.ByteArrayOutputStream;
  42. import java.io.ObjectInput;
  43. import java.io.ObjectInputStream;
  44. import java.io.ObjectOutput;
  45. import java.io.ObjectOutputStream;
  46. import junit.framework.Test;
  47. import junit.framework.TestCase;
  48. import junit.framework.TestSuite;
  49. import org.jfree.chart.axis.DateTickMarkPosition;
  50. /**
  51. * Tests for the {@link DateTickMarkPosition} class.
  52. */
  53. public class DateTickMarkPositionTests extends TestCase {
  54. /**
  55. * Returns the tests as a test suite.
  56. *
  57. * @return The test suite.
  58. */
  59. public static Test suite() {
  60. return new TestSuite(DateTickMarkPositionTests.class);
  61. }
  62. /**
  63. * Constructs a new set of tests.
  64. *
  65. * @param name the name of the tests.
  66. */
  67. public DateTickMarkPositionTests(String name) {
  68. super(name);
  69. }
  70. /**
  71. * Test equals() method.
  72. */
  73. public void testEquals() {
  74. assertEquals(DateTickMarkPosition.START, DateTickMarkPosition.START);
  75. assertEquals(DateTickMarkPosition.MIDDLE, DateTickMarkPosition.MIDDLE);
  76. assertEquals(DateTickMarkPosition.END, DateTickMarkPosition.END);
  77. assertFalse(DateTickMarkPosition.START.equals(null));
  78. assertFalse(DateTickMarkPosition.START.equals(DateTickMarkPosition.END));
  79. assertFalse(DateTickMarkPosition.MIDDLE.equals(DateTickMarkPosition.END));
  80. }
  81. /**
  82. * Two objects that are equal are required to return the same hashCode.
  83. */
  84. public void testHashCode() {
  85. DateTickMarkPosition a1 = DateTickMarkPosition.END;
  86. DateTickMarkPosition a2 = DateTickMarkPosition.END;
  87. assertTrue(a1.equals(a2));
  88. int h1 = a1.hashCode();
  89. int h2 = a2.hashCode();
  90. assertEquals(h1, h2);
  91. }
  92. /**
  93. * Serialize an instance, restore it, and check for equality.
  94. */
  95. public void testSerialization() {
  96. DateTickMarkPosition p1 = DateTickMarkPosition.MIDDLE;
  97. DateTickMarkPosition p2 = null;
  98. try {
  99. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  100. ObjectOutput out = new ObjectOutputStream(buffer);
  101. out.writeObject(p1);
  102. out.close();
  103. ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
  104. p2 = (DateTickMarkPosition) in.readObject();
  105. in.close();
  106. }
  107. catch (Exception e) {
  108. System.out.println(e.toString());
  109. }
  110. assertEquals(p1, p2);
  111. assertTrue(p1 == p2);
  112. }
  113. }