KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > junit > PaintTests


1 /* ========================================================================
2  * JCommon : a free general purpose class 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/jcommon/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  * PaintTests.java
29  * ---------------
30  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: PaintTests.java,v 1.3 2005/10/18 13:16:37 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 23-Oct-2003 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.junit;
44
45 import java.awt.Color JavaDoc;
46 import java.awt.GradientPaint JavaDoc;
47 import java.awt.Paint JavaDoc;
48 import java.awt.TexturePaint JavaDoc;
49 import java.awt.geom.Rectangle2D JavaDoc;
50 import java.awt.image.BufferedImage JavaDoc;
51
52 import junit.framework.Test;
53 import junit.framework.TestCase;
54 import junit.framework.TestSuite;
55
56 /**
57  * Tests for the {@link Paint} interface and known subclasses.
58  */

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

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

75     public PaintTests(final String JavaDoc name) {
76         super(name);
77     }
78
79     /**
80      * Check that the equals() method distinguishes all fields.
81      */

82     public void testColorEquals() {
83         final Paint JavaDoc p1 = new Color JavaDoc(0xFF, 0xEE, 0xDD);
84         final Paint JavaDoc p2 = new Color JavaDoc(0xFF, 0xEE, 0xDD);
85         assertEquals(p1, p2);
86     }
87
88     /**
89      * Two objects that are equal are required to return the same hashCode.
90      */

91     public void testColorHashcode() {
92         final Paint JavaDoc p1 = new Color JavaDoc(0xFF, 0xEE, 0xDD);
93         final Paint JavaDoc p2 = new Color JavaDoc(0xFF, 0xEE, 0xDD);
94         assertTrue(p1.equals(p2));
95         final int h1 = p1.hashCode();
96         final int h2 = p2.hashCode();
97         assertEquals(h1, h2);
98     }
99
100     /**
101      * Check that the equals() method distinguishes all fields.
102      */

103     public void testGradientPaintEquals() {
104         final Paint JavaDoc p1 = new GradientPaint JavaDoc(10.0f, 20.0f, Color.blue, 30.0f, 40.0f, Color.red);
105         final Paint JavaDoc p2 = new GradientPaint JavaDoc(10.0f, 20.0f, Color.blue, 30.0f, 40.0f, Color.red);
106         assertEquals(p1, p2);
107     }
108
109     /**
110      * Check that the equals() method distinguishes all fields.
111      */

112     public void testTexturePaintEquals() {
113         final Paint JavaDoc p1 = new TexturePaint JavaDoc(
114             new BufferedImage JavaDoc(100, 200, BufferedImage.TYPE_INT_RGB), new Rectangle2D.Double JavaDoc()
115         );
116         final Paint JavaDoc p2 = new TexturePaint JavaDoc(
117             new BufferedImage JavaDoc(100, 200, BufferedImage.TYPE_INT_RGB), new Rectangle2D.Double JavaDoc()
118         );
119         assertEquals(p1, p2);
120     }
121
122 }
123
Popular Tags