KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TitleTests.java
29  * ---------------
30  * (C) Copyright 2004, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: TitleTests.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.title.TextTitle;
50 import org.jfree.chart.title.Title;
51 import org.jfree.ui.HorizontalAlignment;
52 import org.jfree.ui.RectangleEdge;
53 import org.jfree.ui.VerticalAlignment;
54
55 /**
56  * Tests for the abstract {@link Title} class.
57  */

58 public class TitleTests extends TestCase {
59
60     /**
61      * Returns the tests as a test suite.
62      *
63      * @return The test suite.
64      */

65     public static Test suite() {
66         return new TestSuite(TitleTests.class);
67     }
68
69     /**
70      * Constructs a new set of tests.
71      *
72      * @param name the name of the tests.
73      */

74     public TitleTests(String JavaDoc name) {
75         super(name);
76     }
77
78     /**
79      * Some checks for the equals() method.
80      */

81     public void testEquals() {
82         
83         // use the TextTitle class because it is a concrete subclass
84
Title t1 = new TextTitle();
85         Title t2 = new TextTitle();
86         assertEquals(t1, t2);
87         
88         t1.setPosition(RectangleEdge.LEFT);
89         assertFalse(t1.equals(t2));
90         t2.setPosition(RectangleEdge.LEFT);
91         assertTrue(t1.equals(t2));
92         
93         t1.setHorizontalAlignment(HorizontalAlignment.RIGHT);
94         assertFalse(t1.equals(t2));
95         t2.setHorizontalAlignment(HorizontalAlignment.RIGHT);
96         assertTrue(t1.equals(t2));
97         
98         t1.setVerticalAlignment(VerticalAlignment.BOTTOM);
99         assertFalse(t1.equals(t2));
100         t2.setVerticalAlignment(VerticalAlignment.BOTTOM);
101         assertTrue(t1.equals(t2));
102         
103     }
104
105     /**
106      * Two objects that are equal are required to return the same hashCode.
107      */

108     public void testHashcode() {
109         TextTitle t1 = new TextTitle();
110         TextTitle t2 = new TextTitle();
111         assertTrue(t1.equals(t2));
112         int h1 = t1.hashCode();
113         int h2 = t2.hashCode();
114         assertEquals(h1, h2);
115     }
116
117 }
118
Popular Tags