001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Denis M. Kishenko
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.Color;
023: import java.awt.GradientPaint;
024: import java.awt.geom.Point2D;
025:
026: import junit.framework.TestCase;
027:
028: public class GradientPaintTest extends TestCase {
029:
030: GradientPaint gp;
031:
032: public void testConstructorBad() {
033: // Regression for HARMONY-1470
034: try {
035: new GradientPaint(1, 2, null, 3, 4, new Color(255), false);
036: fail("expected NPE");
037: } catch (NullPointerException e) {
038: // expected
039: }
040: try {
041: new GradientPaint(1, 2, new Color(255), 3, 4, null, false);
042: fail("expected NPE");
043: } catch (NullPointerException e) {
044: // expected
045: }
046: try {
047: new GradientPaint(1, 2, null, 4, 5, new Color(255));
048: fail("expected NPE");
049: } catch (NullPointerException e) {
050: // expected
051: }
052: try {
053: new GradientPaint(1, 2, new Color(255), 4, 5, null);
054: fail("expected NPE");
055: } catch (NullPointerException e) {
056: // expected
057: }
058: try {
059: new GradientPaint(null, new Color(255),
060: new Point2D.Float(), new Color(255));
061: fail("expected NPE");
062: } catch (NullPointerException e) {
063: // expected
064: }
065: try {
066: new GradientPaint(new Point2D.Float(), null,
067: new Point2D.Float(), new Color(255));
068: fail("expected NPE");
069: } catch (NullPointerException e) {
070: // expected
071: }
072: try {
073: new GradientPaint(new Point2D.Float(), new Color(255),
074: null, new Color(255));
075: fail("expected NPE");
076: } catch (NullPointerException e) {
077: // expected
078: }
079: try {
080: new GradientPaint(new Point2D.Float(), new Color(255),
081: new Point2D.Float(), null);
082: fail("expected NPE");
083: } catch (NullPointerException e) {
084: // expected
085: }
086: }
087:
088: public void testGetPoint1() {
089: gp = new GradientPaint(1, 2, Color.green, 3, 4, Color.blue,
090: true);
091: assertEquals(new Point2D.Float(1, 2), gp.getPoint1());
092: }
093:
094: public void testGetPoint2() {
095: gp = new GradientPaint(1, 2, Color.green, 3, 4, Color.blue,
096: true);
097: assertEquals(new Point2D.Float(3, 4), gp.getPoint2());
098: }
099:
100: public void testGetColor1() {
101: gp = new GradientPaint(1, 2, Color.green, 3, 4, Color.blue,
102: true);
103: assertEquals(Color.green, gp.getColor1());
104: }
105:
106: public void testGetColor2() {
107: gp = new GradientPaint(1, 2, Color.green, 3, 4, Color.blue,
108: true);
109: assertEquals(Color.blue, gp.getColor2());
110: }
111:
112: public void testGetCyclic() {
113: gp = new GradientPaint(1, 2, Color.green, 3, 4, Color.blue,
114: true);
115: assertTrue(gp.isCyclic());
116: gp = new GradientPaint(1, 2, Color.green, 3, 4, Color.blue,
117: false);
118: assertFalse(gp.isCyclic());
119: }
120:
121: public static void main(String[] args) {
122: junit.textui.TestRunner.run(GradientPaintTest.class);
123: }
124:
125: }
|