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.geom;
021:
022: import java.awt.Dimension;
023: import java.awt.Point;
024: import java.awt.Rectangle;
025:
026: import junit.framework.TestCase;
027:
028: // Don't test abstract methods getX(), getY(), getWidth(), getHeight(), isEmpty() and setFrame()
029:
030: public class RectangularShapeTest extends TestCase {
031:
032: Rectangle r;
033:
034: public RectangularShapeTest(String name) {
035: super (name);
036: }
037:
038: @Override
039: protected void setUp() throws Exception {
040: super .setUp();
041: r = new Rectangle(1, 2, 3, 4);
042: }
043:
044: @Override
045: protected void tearDown() throws Exception {
046: r = null;
047: super .tearDown();
048: }
049:
050: public void testGetMinX() {
051: assertEquals(1.0, r.getMinX(), 0.0);
052: }
053:
054: public void testGetMinY() {
055: assertEquals(2.0, r.getMinY(), 0.0);
056: }
057:
058: public void testGetMaxX() {
059: assertEquals(4.0, r.getMaxX(), 0.0);
060: }
061:
062: public void testGetMaxY() {
063: assertEquals(6.0, r.getMaxY(), 0.0);
064: }
065:
066: public void testGetCenterX() {
067: assertEquals(2.5, r.getCenterX(), 0.0);
068: }
069:
070: public void testGetCenterY() {
071: assertEquals(4.0, r.getCenterY(), 0.0);
072: }
073:
074: public void testGetFrame() {
075: assertEquals(new Rectangle2D.Double(1, 2, 3, 4), r.getFrame());
076: }
077:
078: public void testGetBounds() {
079: assertEquals(new Rectangle(1, 2, 3, 4), r.getBounds());
080: assertEquals(new Rectangle(1, 2, 4, 6), new Rectangle2D.Double(
081: 1.3, 2.7, 3.2, 4.5).getBounds());
082: }
083:
084: public void testClone() {
085: assertEquals(r, r.clone());
086: }
087:
088: public void testContainsPoint() {
089: // Just check it works
090: assertTrue(r.contains(new Point(2, 4)));
091: assertTrue(!r.contains(new Point(0, 0)));
092: }
093:
094: public void testContainsRect() {
095: // Just check it works
096: assertTrue(r.contains(new Rectangle(2, 3, 1, 2))); // inside
097: assertTrue(!r.contains(new Rectangle(0, 1, 2, 3))); // intersects
098: assertTrue(!r.contains(new Rectangle(5, 6, 7, 8))); // outside
099: assertTrue(!r.contains(new Rectangle(0, 0, 8, 9))); // cover
100: }
101:
102: public void testIntersectsRect() {
103: // Just check it works
104: assertTrue(r.intersects(new Rectangle(2, 3, 1, 2))); // inside
105: assertTrue(r.intersects(new Rectangle(0, 1, 2, 3))); // intersects
106: assertTrue(!r.intersects(new Rectangle(5, 6, 7, 8))); // outside
107: assertTrue(r.intersects(new Rectangle(0, 0, 8, 9))); // cover
108: }
109:
110: public void testGetPathIterator() {
111: // Just check it works
112: assertTrue(new Arc2D.Double(1, 2, 3, 4, 5, 6, 0)
113: .getPathIterator(null, 0) instanceof FlatteningPathIterator);
114: }
115:
116: public void testSetFrame1() {
117: r.setFrame(5.0, 6.0, 7.0, 8.0);
118: assertEquals(new Rectangle(5, 6, 7, 8), r);
119: }
120:
121: public void testSetFrame2() {
122: r.setFrame(new Point(5, 6), new Dimension(7, 8));
123: assertEquals(new Rectangle(5, 6, 7, 8), r);
124: }
125:
126: public void testSetFrame3() {
127: r.setFrame(new Rectangle(5, 6, 7, 8));
128: assertEquals(new Rectangle(5, 6, 7, 8), r);
129: }
130:
131: public void testSetFrameFromCenterXY1() {
132: r.setFrameFromCenter(5.0, 6.0, 7.0, 9.0);
133: assertEquals(new Rectangle(3, 3, 4, 6), r);
134: }
135:
136: public void testSetFrameFromCenterXY2() {
137: r.setFrameFromCenter(5.0, 6.0, 7.0, 3.0);
138: assertEquals(new Rectangle(3, 3, 4, 6), r);
139: }
140:
141: public void testSetFrameFromCenterXY3() {
142: r.setFrameFromCenter(5.0, 6.0, 3.0, 3.0);
143: assertEquals(new Rectangle(3, 3, 4, 6), r);
144: }
145:
146: public void testSetFrameFromCenterXY4() {
147: r.setFrameFromCenter(5.0, 6.0, 3.0, 9.0);
148: assertEquals(new Rectangle(3, 3, 4, 6), r);
149: }
150:
151: public void testSetFrameFromCenterPP1() {
152: r.setFrameFromCenter(new Point(5, 6), new Point(7, 9));
153: assertEquals(new Rectangle(3, 3, 4, 6), r);
154: }
155:
156: public void testSetFrameFromCenterPP2() {
157: r.setFrameFromCenter(new Point(5, 6), new Point(7, 3));
158: assertEquals(new Rectangle(3, 3, 4, 6), r);
159: }
160:
161: public void testSetFrameFromCenterPP3() {
162: r.setFrameFromCenter(new Point(5, 6), new Point(3, 3));
163: assertEquals(new Rectangle(3, 3, 4, 6), r);
164: }
165:
166: public void testSetFrameFromCenterPP4() {
167: r.setFrameFromCenter(new Point(5, 6), new Point(3, 9));
168: assertEquals(new Rectangle(3, 3, 4, 6), r);
169: }
170:
171: public void testSetFrameFromDiagonalXY1() {
172: r.setFrameFromDiagonal(5.0, 6.0, 7.0, 9.0);
173: assertEquals(new Rectangle(5, 6, 2, 3), r);
174: }
175:
176: public void testSetFrameFromDiagonalXY2() {
177: r.setFrameFromDiagonal(5.0, 6.0, 7.0, 3.0);
178: assertEquals(new Rectangle(5, 3, 2, 3), r);
179: }
180:
181: public void testSetFrameFromDiagonalXY3() {
182: r.setFrameFromDiagonal(5.0, 6.0, 3.0, 3.0);
183: assertEquals(new Rectangle(3, 3, 2, 3), r);
184: }
185:
186: public void testSetFrameFromDiagonalXY4() {
187: r.setFrameFromDiagonal(5.0, 6.0, 3.0, 9.0);
188: assertEquals(new Rectangle(3, 6, 2, 3), r);
189: }
190:
191: public void testSetFrameFromDiagonalPP1() {
192: r.setFrameFromDiagonal(new Point(5, 6), new Point(7, 9));
193: assertEquals(new Rectangle(5, 6, 2, 3), r);
194: }
195:
196: public void testSetFrameFromDiagonalPP2() {
197: r.setFrameFromDiagonal(new Point(5, 6), new Point(7, 3));
198: assertEquals(new Rectangle(5, 3, 2, 3), r);
199: }
200:
201: public void testSetFrameFromDiagonalPP3() {
202: r.setFrameFromDiagonal(new Point(5, 6), new Point(3, 3));
203: assertEquals(new Rectangle(3, 3, 2, 3), r);
204: }
205:
206: public void testSetFrameFromDiagonalPP4() {
207: r.setFrameFromDiagonal(new Point(5, 6), new Point(3, 9));
208: assertEquals(new Rectangle(3, 6, 2, 3), r);
209: }
210:
211: public static void main(String[] args) {
212: junit.textui.TestRunner.run(RectangularShapeTest.class);
213: }
214:
215: }
|