KickJava   Java API By Example, From Geeks To Geeks.

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


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 nextapp.echo2.app.Insets;
34 import junit.framework.TestCase;
35
36 /**
37  * Unit test(s) for the <code>nextapp.echo2.app.Alignment</code> property
38  * value object.
39  */

40 public class InsetsTest extends TestCase {
41     
42     private static final Extent PX_1 = new Extent(1, Extent.PX);
43     private static final Extent PX_2 = new Extent(2, Extent.PX);
44     private static final Extent PX_3 = new Extent(3, Extent.PX);
45     private static final Extent PX_4 = new Extent(4, Extent.PX);
46     
47     /**
48      * Test all-margins equal constructor.
49      */

50     public void testConstructorEqual() {
51         Insets insets = new Insets(PX_1);
52         assertEquals(insets.getLeft(), PX_1);
53         assertEquals(insets.getTop(), PX_1);
54         assertEquals(insets.getRight(), PX_1);
55         assertEquals(insets.getBottom(), PX_1);
56     }
57     
58     /**
59      * Test horizontal = vertical constructor.
60      */

61     public void testConstructorHV() {
62         Insets insets = new Insets(PX_1, PX_2);
63         assertEquals(insets.getLeft(), PX_1);
64         assertEquals(insets.getTop(), PX_2);
65         assertEquals(insets.getRight(), PX_1);
66         assertEquals(insets.getBottom(), PX_2);
67     }
68     
69     /**
70      * Test all-margins specific constructor.
71      */

72     public void testConstructorSpecific() {
73         Insets insets = new Insets(PX_1, PX_2, PX_3, PX_4);
74         assertEquals(insets.getLeft(), PX_1);
75         assertEquals(insets.getTop(), PX_2);
76         assertEquals(insets.getRight(), PX_3);
77         assertEquals(insets.getBottom(), PX_4);
78     }
79     
80     /**
81      * Test integer/pixel all-margins equal constructor.
82      */

83     public void testConstructorPixelEqual() {
84         Insets insets = new Insets(1);
85         assertEquals(insets.getLeft(), PX_1);
86         assertEquals(insets.getTop(), PX_1);
87         assertEquals(insets.getRight(), PX_1);
88         assertEquals(insets.getBottom(), PX_1);
89     }
90     
91     /**
92      * Test integer/pixel horizontal = vertical constructor.
93      */

94     public void testConstructorPixelHV() {
95         Insets insets = new Insets(1, 2);
96         assertEquals(insets.getLeft(), PX_1);
97         assertEquals(insets.getTop(), PX_2);
98         assertEquals(insets.getRight(), PX_1);
99         assertEquals(insets.getBottom(), PX_2);
100     }
101     
102     /**
103      * Test integer/pixel all-margins specific constructor.
104      */

105     public void testConstructorPixelSpecific() {
106         Insets insets = new Insets(1, 2, 3, 4);
107         assertEquals(insets.getLeft(), PX_1);
108         assertEquals(insets.getTop(), PX_2);
109         assertEquals(insets.getRight(), PX_3);
110         assertEquals(insets.getBottom(), PX_4);
111     }
112     
113     /**
114      * Test <code>equals()</code> method.
115      */

116     public void testEquals() {
117         assertEquals(new Insets(1), new Insets(1));
118         assertEquals(new Insets(1, 2), new Insets(1, 2));
119         assertEquals(new Insets(1, 2, 3, 4), new Insets(1, 2, 3, 4));
120         assertEquals(new Insets(null, null, null, null), new Insets(null, null, null, null));
121         assertFalse(new Insets(1, 2, 3, 4).equals(new Insets(1, 2, 3, 5)));
122         assertFalse(new Insets(1, 2, 3, 4).equals(new Insets(1, 2, 5, 4)));
123         assertFalse(new Insets(1, 2, 3, 4).equals(new Insets(1, 5, 3, 4)));
124         assertFalse(new Insets(1, 2, 3, 4).equals(new Insets(5, 2, 3, 4)));
125         assertTrue(new Insets(PX_1, PX_2, PX_3, PX_4).equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
126         assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4).equals(new Insets(null, PX_2, PX_3, PX_4)));
127         assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4).equals(new Insets(PX_1, null, PX_3, PX_4)));
128         assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4).equals(new Insets(PX_1, PX_2, null, PX_4)));
129         assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4).equals(new Insets(PX_1, PX_2, PX_3, null)));
130         assertFalse(new Insets(null, PX_2, PX_3, PX_4).equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
131         assertFalse(new Insets(PX_1, null, PX_3, PX_4).equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
132         assertFalse(new Insets(PX_1, PX_2, null, PX_4).equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
133         assertFalse(new Insets(PX_1, PX_2, PX_3, null).equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
134     }
135 }
136
Popular Tags