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
  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 License
  20. * along with this library; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  24. * in the United States and other countries.]
  25. *
  26. * ---------------
  27. * TitleTests.java
  28. * ---------------
  29. * (C) Copyright 2004, by Object Refinery Limited and Contributors.
  30. *
  31. * Original Author: David Gilbert (for Object Refinery Limited);
  32. * Contributor(s): -;
  33. *
  34. * $Id: TitleTests.java,v 1.4 2005/02/04 17:05:45 mungady Exp $
  35. *
  36. * Changes
  37. * -------
  38. * 17-Feb-2004 : Version 1 (DG);
  39. *
  40. */
  41. package org.jfree.chart.title.junit;
  42. import junit.framework.Test;
  43. import junit.framework.TestCase;
  44. import junit.framework.TestSuite;
  45. import org.jfree.chart.title.TextTitle;
  46. import org.jfree.chart.title.Title;
  47. import org.jfree.ui.HorizontalAlignment;
  48. import org.jfree.ui.RectangleEdge;
  49. import org.jfree.ui.VerticalAlignment;
  50. /**
  51. * Tests for the abstract {@link Title} class.
  52. */
  53. public class TitleTests 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(TitleTests.class);
  61. }
  62. /**
  63. * Constructs a new set of tests.
  64. *
  65. * @param name the name of the tests.
  66. */
  67. public TitleTests(String name) {
  68. super(name);
  69. }
  70. /**
  71. * Some checks for the equals() method.
  72. */
  73. public void testEquals() {
  74. // use the TextTitle class because it is a concrete subclass
  75. Title t1 = new TextTitle();
  76. Title t2 = new TextTitle();
  77. assertEquals(t1, t2);
  78. t1.setPosition(RectangleEdge.LEFT);
  79. assertFalse(t1.equals(t2));
  80. t2.setPosition(RectangleEdge.LEFT);
  81. assertTrue(t1.equals(t2));
  82. t1.setHorizontalAlignment(HorizontalAlignment.RIGHT);
  83. assertFalse(t1.equals(t2));
  84. t2.setHorizontalAlignment(HorizontalAlignment.RIGHT);
  85. assertTrue(t1.equals(t2));
  86. t1.setVerticalAlignment(VerticalAlignment.BOTTOM);
  87. assertFalse(t1.equals(t2));
  88. t2.setVerticalAlignment(VerticalAlignment.BOTTOM);
  89. assertTrue(t1.equals(t2));
  90. }
  91. /**
  92. * Two objects that are equal are required to return the same hashCode.
  93. */
  94. public void testHashcode() {
  95. TextTitle t1 = new TextTitle();
  96. TextTitle t2 = new TextTitle();
  97. assertTrue(t1.equals(t2));
  98. int h1 = t1.hashCode();
  99. int h2 = t2.hashCode();
  100. assertEquals(h1, h2);
  101. }
  102. }