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. * ImageTitleTests.java
  28. * --------------------
  29. * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
  30. *
  31. * Original Author: David Gilbert (for Object Refinery Limited);
  32. * Contributor(s): -;
  33. *
  34. * $Id: ImageTitleTests.java,v 1.3 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.JFreeChart;
  46. import org.jfree.chart.title.ImageTitle;
  47. /**
  48. * Tests for the {@link ImageTitle} class.
  49. */
  50. public class ImageTitleTests extends TestCase {
  51. /**
  52. * Returns the tests as a test suite.
  53. *
  54. * @return The test suite.
  55. */
  56. public static Test suite() {
  57. return new TestSuite(ImageTitleTests.class);
  58. }
  59. /**
  60. * Constructs a new set of tests.
  61. *
  62. * @param name the name of the tests.
  63. */
  64. public ImageTitleTests(String name) {
  65. super(name);
  66. }
  67. /**
  68. * Check that the equals() method distinguishes all fields.
  69. */
  70. public void testEquals() {
  71. ImageTitle t1 = new ImageTitle(JFreeChart.INFO.getLogo());
  72. ImageTitle t2 = new ImageTitle(JFreeChart.INFO.getLogo());
  73. assertEquals(t1, t2);
  74. }
  75. /**
  76. * Two objects that are equal are required to return the same hashCode.
  77. */
  78. public void testHashcode() {
  79. ImageTitle t1 = new ImageTitle(JFreeChart.INFO.getLogo());
  80. ImageTitle t2 = new ImageTitle(JFreeChart.INFO.getLogo());
  81. assertTrue(t1.equals(t2));
  82. int h1 = t1.hashCode();
  83. int h2 = t2.hashCode();
  84. assertEquals(h1, h2);
  85. }
  86. /**
  87. * Confirm that cloning works.
  88. */
  89. public void testCloning() {
  90. ImageTitle t1 = new ImageTitle(JFreeChart.INFO.getLogo());
  91. ImageTitle t2 = null;
  92. try {
  93. t2 = (ImageTitle) t1.clone();
  94. }
  95. catch (CloneNotSupportedException e) {
  96. System.err.println("ImageTitleTests.testCloning: failed to clone.");
  97. }
  98. assertTrue(t1 != t2);
  99. assertTrue(t1.getClass() == t2.getClass());
  100. assertTrue(t1.equals(t2));
  101. }
  102. /**
  103. * Serialize an instance, restore it, and check for equality.
  104. */
  105. public void testSerialization() {
  106. // TODO: add serialization support for images
  107. }
  108. }