001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ---------------
028: * PaintTests.java
029: * ---------------
030: * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: PaintTests.java,v 1.3 2005/10/18 13:16:37 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 23-Oct-2003 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.junit;
044:
045: import java.awt.Color;
046: import java.awt.GradientPaint;
047: import java.awt.Paint;
048: import java.awt.TexturePaint;
049: import java.awt.geom.Rectangle2D;
050: import java.awt.image.BufferedImage;
051:
052: import junit.framework.Test;
053: import junit.framework.TestCase;
054: import junit.framework.TestSuite;
055:
056: /**
057: * Tests for the {@link Paint} interface and known subclasses.
058: */
059: public class PaintTests extends TestCase {
060:
061: /**
062: * Returns the tests as a test suite.
063: *
064: * @return the test suite.
065: */
066: public static Test suite() {
067: return new TestSuite(PaintTests.class);
068: }
069:
070: /**
071: * Constructs a new set of tests.
072: *
073: * @param name the name of the tests.
074: */
075: public PaintTests(final String name) {
076: super (name);
077: }
078:
079: /**
080: * Check that the equals() method distinguishes all fields.
081: */
082: public void testColorEquals() {
083: final Paint p1 = new Color(0xFF, 0xEE, 0xDD);
084: final Paint p2 = new Color(0xFF, 0xEE, 0xDD);
085: assertEquals(p1, p2);
086: }
087:
088: /**
089: * Two objects that are equal are required to return the same hashCode.
090: */
091: public void testColorHashcode() {
092: final Paint p1 = new Color(0xFF, 0xEE, 0xDD);
093: final Paint p2 = new Color(0xFF, 0xEE, 0xDD);
094: assertTrue(p1.equals(p2));
095: final int h1 = p1.hashCode();
096: final int h2 = p2.hashCode();
097: assertEquals(h1, h2);
098: }
099:
100: /**
101: * Check that the equals() method distinguishes all fields.
102: */
103: public void testGradientPaintEquals() {
104: final Paint p1 = new GradientPaint(10.0f, 20.0f, Color.blue,
105: 30.0f, 40.0f, Color.red);
106: final Paint p2 = new GradientPaint(10.0f, 20.0f, Color.blue,
107: 30.0f, 40.0f, Color.red);
108: assertEquals(p1, p2);
109: }
110:
111: /**
112: * Check that the equals() method distinguishes all fields.
113: */
114: public void testTexturePaintEquals() {
115: final Paint p1 = new TexturePaint(new BufferedImage(100, 200,
116: BufferedImage.TYPE_INT_RGB), new Rectangle2D.Double());
117: final Paint p2 = new TexturePaint(new BufferedImage(100, 200,
118: BufferedImage.TYPE_INT_RGB), new Rectangle2D.Double());
119: assertEquals(p1, p2);
120: }
121:
122: }
|