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.Dimension;
023:
024: public class DimensionTest extends SerializeTestCase {
025:
026: static {
027: SERIALIZATION_TEST = true;
028: }
029:
030: Dimension d;
031:
032: public DimensionTest(String name) {
033: super (name);
034: }
035:
036: @Override
037: protected void setUp() throws Exception {
038: super .setUp();
039: d = new Dimension(2, 3);
040: }
041:
042: @Override
043: protected void tearDown() throws Exception {
044: d = null;
045: super .tearDown();
046: }
047:
048: public void testCreate1() {
049: assertEquals(new Dimension(), new Dimension(0, 0));
050: }
051:
052: public void testCreate2() {
053: assertEquals(new Dimension(new Dimension(4, 5)), new Dimension(
054: 4, 5));
055: }
056:
057: public void testCreate3() {
058: assertEquals(new Dimension(4, 5), new Dimension(4, 5));
059: }
060:
061: public void testEquals() {
062: assertTrue(d.equals(new Dimension(2, 3)));
063: assertTrue(!d.equals(new Dimension(2, 4)));
064: assertTrue(!d.equals(new Dimension(1, 3)));
065: assertTrue(!d.equals(new Dimension(1, 4)));
066: }
067:
068: public void testGetWidth() {
069: assertEquals(d.getWidth(), 2.0, 0.0);
070: }
071:
072: public void testGetHeight() {
073: assertEquals(d.getHeight(), 3.0, 0.0);
074: }
075:
076: public void testGetSize() {
077: assertEquals(d.getSize(), new Dimension(2, 3));
078: }
079:
080: public void testHashCode() {
081: assertTrue(d.hashCode() == new Dimension(2, 3).hashCode());
082: assertTrue(d.hashCode() != new Dimension(2, 4).hashCode());
083: assertTrue(d.hashCode() != new Dimension(1, 3).hashCode());
084: assertTrue(d.hashCode() != new Dimension(1, 4).hashCode());
085: }
086:
087: public void testSetSize1() {
088: d.setSize(new Dimension(4, 5));
089: assertEquals(d, new Dimension(4, 5));
090: }
091:
092: public void testSetSize2() {
093: d.setSize(4, 5);
094: assertEquals(d, new Dimension(4, 5));
095: }
096:
097: public void testSetSize3() {
098: d.setSize(4.0, 5.0);
099: assertEquals(d, new Dimension(4, 5));
100: d.setSize(4.3, 5.7);
101: assertEquals(d, new Dimension(5, 6));
102: d.setSize(3.5, 4.5);
103: assertEquals(d, new Dimension(4, 5));
104: }
105:
106: public void testToString() {
107: assertEquals(d.toString(),
108: "java.awt.Dimension[width=2,height=3]");
109: }
110:
111: public void testSerializeRead1() {
112: checkRead(new Dimension());
113: }
114:
115: public void testSerializeRead2() {
116: checkRead(new Dimension(1, 2));
117: }
118:
119: public void testSerializeWrite1() {
120: checkWrite(new Dimension());
121: }
122:
123: public void testSerializeWrite2() {
124: checkWrite(new Dimension(1, 2));
125: }
126:
127: public void createSerializeTemplates() {
128: saveSerialized(new Dimension());
129: saveSerialized(new Dimension(1, 2));
130: }
131:
132: public static void main(String[] args) {
133: // new DimensionTest("").createSerializeTemplates();
134: junit.textui.TestRunner.run(DimensionTest.class);
135: }
136:
137: }
|