KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > test > ExtentTest


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.app.test;
31
32 import nextapp.echo2.app.Extent;
33 import junit.framework.TestCase;
34
35 /**
36  * Unit test(s) for the <code>nextapp.echo2.app.Extent</code> property
37  * value object.
38  */

39 public class ExtentTest extends TestCase {
40     
41     private static final Extent _50_CENTIMETERS = new Extent(50, Extent.CM);
42     private static final Extent _50_EM = new Extent(50, Extent.EM);
43     private static final Extent _50_EX = new Extent(50, Extent.EX);
44     private static final Extent _50_INCHES = new Extent(50, Extent.IN);
45     private static final Extent _50_MILLIMETERS = new Extent(50, Extent.MM);
46     private static final Extent _50_PERCENT = new Extent(50, Extent.PERCENT);
47     private static final Extent _50_PICAS = new Extent(50, Extent.PC);
48     private static final Extent _50_PIXELS = new Extent(50, Extent.PX);
49     private static final Extent _50_POINT = new Extent(50, Extent.PT);
50
51     /**
52      * Test extent addition.
53      */

54     public void testAdd() {
55         assertEquals(Extent.add(_50_EM, _50_EM), new Extent(100, Extent.EM));
56     }
57     
58     /**
59      * Test equality.
60      */

61     public void testEquals() {
62         assertEquals(new Extent(20, Extent.CM), new Extent(20, Extent.CM));
63         assertFalse(new Extent(20, Extent.CM).equals(new Extent(21, Extent.CM)));
64         assertFalse(new Extent(20, Extent.MM).equals(new Extent(21, Extent.CM)));
65     }
66
67     /**
68      * Test <code>Comparable</code> implementation.
69      */

70     public void testCompareTo() {
71         assertTrue(_50_INCHES.compareTo(_50_INCHES) == 0);
72         assertTrue(_50_CENTIMETERS.compareTo(_50_INCHES) < 0);
73         assertTrue(_50_MILLIMETERS.compareTo(_50_INCHES) < 0);
74         assertTrue(_50_PICAS.compareTo(_50_INCHES) < 0);
75         assertTrue(_50_POINT.compareTo(_50_INCHES) < 0);
76         assertTrue(_50_INCHES.compareTo(_50_CENTIMETERS) == 0 - _50_CENTIMETERS.compareTo(_50_INCHES));
77         assertTrue(_50_POINT.compareTo(_50_INCHES) == 0 - _50_INCHES.compareTo(_50_POINT));
78         
79         assertTrue(_50_EX.compareTo(_50_PIXELS) != 0);
80         assertTrue(_50_EX.compareTo(_50_PIXELS) == 0 - _50_PIXELS.compareTo(_50_EX));
81     }
82
83     /**
84      * Test <code>isComparableTo()</code>.
85      */

86     public void testIsComparableTo() {
87         assertTrue(_50_CENTIMETERS.isComparableTo(_50_MILLIMETERS));
88         assertTrue(_50_INCHES.isComparableTo(_50_MILLIMETERS));
89         assertTrue(_50_PICAS.isComparableTo(_50_MILLIMETERS));
90         assertTrue(_50_POINT.isComparableTo(_50_MILLIMETERS));
91         assertTrue(_50_PIXELS.isComparableTo(_50_PIXELS));
92         assertFalse(_50_PERCENT.isComparableTo(_50_MILLIMETERS));
93         assertFalse(_50_PERCENT.isComparableTo(_50_PIXELS));
94     }
95
96     /**
97      * Test <code>isEnglish()</code>.
98      */

99     public void testIsEnglish() {
100         assertFalse(_50_CENTIMETERS.isEnglish());
101         assertFalse(_50_EM.isEnglish());
102         assertFalse(_50_EX.isEnglish());
103         assertTrue(_50_INCHES.isEnglish());
104         assertFalse(_50_MILLIMETERS.isEnglish());
105         assertFalse(_50_PERCENT.isEnglish());
106         assertTrue(_50_PICAS.isEnglish());
107         assertFalse(_50_PIXELS.isEnglish());
108         assertTrue(_50_POINT.isEnglish());
109     }
110
111     /**
112      * Test <code>isSI()</code>.
113      */

114     public void testIsSI() {
115         assertTrue(_50_CENTIMETERS.isSI());
116         assertFalse(_50_EM.isSI());
117         assertFalse(_50_EX.isSI());
118         assertFalse(_50_INCHES.isSI());
119         assertTrue(_50_MILLIMETERS.isSI());
120         assertFalse(_50_PERCENT.isSI());
121         assertFalse(_50_PICAS.isSI());
122         assertFalse(_50_PIXELS.isSI());
123         assertFalse(_50_POINT.isSI());
124     }
125
126     /**
127      * Test <code>isPercentage()</code>.
128      */

129     public void testIsPercentage() {
130         assertFalse(_50_CENTIMETERS.isPercentage());
131         assertFalse(_50_EM.isPercentage());
132         assertFalse(_50_EX.isPercentage());
133         assertFalse(_50_INCHES.isPercentage());
134         assertFalse(_50_MILLIMETERS.isPercentage());
135         assertTrue(_50_PERCENT.isPercentage());
136         assertFalse(_50_PICAS.isPercentage());
137         assertFalse(_50_PIXELS.isPercentage());
138         assertFalse(_50_POINT.isPercentage());
139     }
140
141     /**
142      * Test <code>isPrint()</code>.
143      */

144     public void testIsPrint() {
145         assertTrue(_50_CENTIMETERS.isPrint());
146         assertFalse(_50_EM.isPrint());
147         assertFalse(_50_EX.isPrint());
148         assertTrue(_50_INCHES.isPrint());
149         assertTrue(_50_MILLIMETERS.isPrint());
150         assertFalse(_50_PERCENT.isPrint());
151         assertTrue(_50_PICAS.isPrint());
152         assertFalse(_50_PIXELS.isPrint());
153         assertTrue(_50_POINT.isPrint());
154     }
155
156     /**
157      * Test conversion to millimeters.
158      */

159     public void testToMm() {
160         assertEquals(20, new Extent(20, Extent.MM).toMm());
161         assertEquals(20, new Extent(2, Extent.CM).toMm());
162         assertEquals(2540, new Extent(100, Extent.IN).toMm());
163         assertEquals(2540, new Extent(7200, Extent.PT).toMm());
164         assertEquals(2540, new Extent(600, Extent.PC).toMm());
165         
166         try {
167             new Extent(1, Extent.EM).toMm();
168             fail("Did not throw IllegalStateException.");
169         } catch (IllegalStateException JavaDoc ex) {
170             // Expected.
171
}
172         
173         try {
174             new Extent(1, Extent.EX).toMm();
175             fail("Did not throw IllegalStateException.");
176         } catch (IllegalStateException JavaDoc ex) {
177             // Expected.
178
}
179         
180         try {
181             new Extent(1, Extent.PERCENT).toMm();
182             fail("Did not throw IllegalStateException.");
183         } catch (IllegalStateException JavaDoc ex) {
184             // Expected.
185
}
186         
187         try {
188             new Extent(1, Extent.PX).toMm();
189             fail("Did not throw IllegalStateException.");
190         } catch (IllegalStateException JavaDoc ex) {
191             // Expected.
192
}
193     }
194
195     /**
196      * Test conversion to points.
197      */

198     public void testToPoint() {
199         assertEquals(20, new Extent(20, Extent.PT).toPoint());
200         assertEquals(7200, new Extent(2540, Extent.MM).toPoint());
201         assertEquals(7200, new Extent(254, Extent.CM).toPoint());
202         assertEquals(7200, new Extent(100, Extent.IN).toPoint());
203         assertEquals(7200, new Extent(600, Extent.PC).toPoint());
204         
205         try {
206             new Extent(1, Extent.EM).toPoint();
207             fail("Did not throw IllegalStateException.");
208         } catch (IllegalStateException JavaDoc ex) {
209             // Expected.
210
}
211         
212         try {
213             new Extent(1, Extent.EX).toPoint();
214             fail("Did not throw IllegalStateException.");
215         } catch (IllegalStateException JavaDoc ex) {
216             // Expected.
217
}
218         
219         try {
220             new Extent(1, Extent.PERCENT).toPoint();
221             fail("Did not throw IllegalStateException.");
222         } catch (IllegalStateException JavaDoc ex) {
223             // Expected.
224
}
225         
226         try {
227             new Extent(1, Extent.PX).toPoint();
228             fail("Did not throw IllegalStateException.");
229         } catch (IllegalStateException JavaDoc ex) {
230             // Expected.
231
}
232     }
233 }
234
Popular Tags