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 Elena V. Sayapina
019: * @version $Revision: 1.3 $
020: */package javax.print.attribute.standard;
021:
022: import junit.framework.TestCase;
023:
024: public class MediaPrintableAreaTest extends TestCase {
025:
026: public static void main(String[] args) {
027: junit.textui.TestRunner.run(MediaPrintableAreaTest.class);
028: }
029:
030: static {
031: System.out.println("MediaPrintableArea testing...");
032: }
033:
034: MediaPrintableArea mpa1, mpa2;
035:
036: /*
037: * MediaPrintableArea(int x, int y, int width, int height,
038: * int units) constructors testing.
039: */
040: public void testMediaPrintableArea() {
041: try {
042: mpa1 = new MediaPrintableArea(20, 20, 100, 100, 0);
043: fail("Constructor doesn't throw IllegalArgumentException if "
044: + "units < 1");
045: } catch (IllegalArgumentException e) {
046:
047: }
048: try {
049: mpa1 = new MediaPrintableArea(-2, 2, 1, 1, 1);
050: fail("Constructor doesn't throw IllegalArgumentException if "
051: + "x < 0");
052: } catch (IllegalArgumentException e) {
053:
054: }
055: }
056:
057: /*
058: * MediaPrintableArea(float x, float y, float width, float height,
059: * int units) constructors testing.
060: */
061: public void testMediaPrintableArea1() {
062:
063: mpa1 = new MediaPrintableArea(0.4f, 0.5f, 9.9f, 3.4f, 1);
064: assertEquals(0.0f, mpa1.getX(1), 0.001f);
065: assertEquals(1.0f, mpa1.getY(1), 0.001f);
066: assertEquals(3.0f, mpa1.getHeight(1), 0.001f);
067: assertEquals(10.0f, mpa1.getWidth(1), 0.001f);
068: }
069:
070: /*
071: * hashCode() method testing. Tests if two object is the same they must
072: * have the same hashCodes.
073: */
074: public void testHashCode() {
075: mpa1 = new MediaPrintableArea(20, 20, 100, 100,
076: MediaPrintableArea.INCH);
077: mpa2 = new MediaPrintableArea(20, 20, 100, 100,
078: MediaPrintableArea.INCH);
079: assertEquals(mpa1.hashCode(), mpa2.hashCode());
080: }
081:
082: /*
083: * hashCode() method testing. Tests if two object is different they should
084: * have different hashCodes.
085: */
086: public void testHashCode1() {
087: mpa1 = new MediaPrintableArea(20, 20, 100, 100,
088: MediaPrintableArea.INCH);
089: mpa2 = new MediaPrintableArea(20, 20, 100, 100,
090: MediaPrintableArea.MM);
091: assertFalse(mpa1.hashCode() == mpa2.hashCode());
092: }
093:
094: /*
095: * equals(Object object) method testing.
096: */
097: public void testEqualsObject() {
098:
099: mpa1 = new MediaPrintableArea(1, 1, 1, 1,
100: MediaPrintableArea.INCH);
101: mpa2 = new MediaPrintableArea(25400, 25400, 25400, 25400, 1);
102: assertTrue(mpa1.equals(mpa2));
103:
104: mpa1 = new MediaPrintableArea(20, 20, 10, 10,
105: MediaPrintableArea.INCH);
106: mpa2 = new MediaPrintableArea(20, 20, 10, 10,
107: MediaPrintableArea.MM);
108: assertFalse(mpa1.equals(mpa2));
109:
110: mpa2 = null;
111: assertFalse(mpa1.equals(mpa2));
112: }
113:
114: /*
115: * getCategory() method testing.
116: */
117: public void testGetCategory() {
118: mpa1 = new MediaPrintableArea(1, 1, 1, 1, 1);
119: assertEquals(MediaPrintableArea.class, mpa1.getCategory());
120: }
121:
122: /*
123: * getName() method testing.
124: */
125: public void testGetName() {
126: mpa1 = new MediaPrintableArea(1, 1, 1, 1, 1);
127: assertEquals("media-printable-area", mpa1.getName());
128: }
129:
130: /*
131: * getX(), getY(), getHeight(), getHeight() methods testing.
132: */
133: public void testGetX() {
134: mpa1 = new MediaPrintableArea(1, 100, 1, 1, 1);
135: assertEquals(0.01f, mpa1.getX(100), 0.01f);
136: assertEquals(1.0f, mpa1.getY(100), 0.01f);
137: assertEquals(0.333f, mpa1.getWidth(3), 0.001f);
138: assertEquals(0.05f, mpa1.getHeight(20), 0.01f);
139: }
140:
141: /*
142: * toString() method checking.
143: */
144: public void testToString() {
145:
146: mpa1 = new MediaPrintableArea(20.0f, 20.0f, 100.0f, 100.0f,
147: 254000);
148: //System.out.println(mpa1.toString(254000, "inch"));
149:
150: mpa1 = new MediaPrintableArea(20, 20, 100, 100, 1000);
151: //System.out.println(mpa1.toString());
152: }
153:
154: }
|