KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > title > junit > ImageTitleTests


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
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  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * --------------------
28  * ImageTitleTests.java
29  * --------------------
30  * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: ImageTitleTests.java,v 1.1.2.1 2006/10/03 15:41:29 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 17-Feb-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.title.junit;
44
45 import junit.framework.Test;
46 import junit.framework.TestCase;
47 import junit.framework.TestSuite;
48
49 import org.jfree.chart.JFreeChart;
50 import org.jfree.chart.title.ImageTitle;
51
52 /**
53  * Tests for the {@link ImageTitle} class.
54  */

55 public class ImageTitleTests extends TestCase {
56
57     /**
58      * Returns the tests as a test suite.
59      *
60      * @return The test suite.
61      */

62     public static Test suite() {
63         return new TestSuite(ImageTitleTests.class);
64     }
65
66     /**
67      * Constructs a new set of tests.
68      *
69      * @param name the name of the tests.
70      */

71     public ImageTitleTests(String JavaDoc name) {
72         super(name);
73     }
74
75     /**
76      * Check that the equals() method distinguishes all fields.
77      */

78     public void testEquals() {
79         ImageTitle t1 = new ImageTitle(JFreeChart.INFO.getLogo());
80         ImageTitle t2 = new ImageTitle(JFreeChart.INFO.getLogo());
81         assertEquals(t1, t2);
82     }
83
84     /**
85      * Two objects that are equal are required to return the same hashCode.
86      */

87     public void testHashcode() {
88         ImageTitle t1 = new ImageTitle(JFreeChart.INFO.getLogo());
89         ImageTitle t2 = new ImageTitle(JFreeChart.INFO.getLogo());
90         assertTrue(t1.equals(t2));
91         int h1 = t1.hashCode();
92         int h2 = t2.hashCode();
93         assertEquals(h1, h2);
94     }
95     
96     /**
97      * Confirm that cloning works.
98      */

99     public void testCloning() {
100         ImageTitle t1 = new ImageTitle(JFreeChart.INFO.getLogo());
101         ImageTitle t2 = null;
102         try {
103             t2 = (ImageTitle) t1.clone();
104         }
105         catch (CloneNotSupportedException JavaDoc e) {
106             System.err.println("ImageTitleTests.testCloning: failed to clone.");
107         }
108         assertTrue(t1 != t2);
109         assertTrue(t1.getClass() == t2.getClass());
110         assertTrue(t1.equals(t2));
111     }
112
113     /**
114      * Serialize an instance, restore it, and check for equality.
115      */

116     public void testSerialization() {
117
118         // TODO: add serialization support for images
119

120     }
121     
122     private static final double EPSILON = 0.00000001;
123     
124     /**
125      * Check the width and height.
126      */

127     public void testWidthAndHeight() {
128         ImageTitle t1 = new ImageTitle(JFreeChart.INFO.getLogo());
129         assertEquals(100, t1.getWidth(), EPSILON);
130         assertEquals(100, t1.getHeight(), EPSILON);
131     }
132
133 }
134
Popular Tags