001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app.test;
031:
032: import nextapp.echo2.app.Extent;
033: import nextapp.echo2.app.Insets;
034: import junit.framework.TestCase;
035:
036: /**
037: * Unit test(s) for the <code>nextapp.echo2.app.Alignment</code> property
038: * value object.
039: */
040: public class InsetsTest extends TestCase {
041:
042: private static final Extent PX_1 = new Extent(1, Extent.PX);
043: private static final Extent PX_2 = new Extent(2, Extent.PX);
044: private static final Extent PX_3 = new Extent(3, Extent.PX);
045: private static final Extent PX_4 = new Extent(4, Extent.PX);
046:
047: /**
048: * Test all-margins equal constructor.
049: */
050: public void testConstructorEqual() {
051: Insets insets = new Insets(PX_1);
052: assertEquals(insets.getLeft(), PX_1);
053: assertEquals(insets.getTop(), PX_1);
054: assertEquals(insets.getRight(), PX_1);
055: assertEquals(insets.getBottom(), PX_1);
056: }
057:
058: /**
059: * Test horizontal = vertical constructor.
060: */
061: public void testConstructorHV() {
062: Insets insets = new Insets(PX_1, PX_2);
063: assertEquals(insets.getLeft(), PX_1);
064: assertEquals(insets.getTop(), PX_2);
065: assertEquals(insets.getRight(), PX_1);
066: assertEquals(insets.getBottom(), PX_2);
067: }
068:
069: /**
070: * Test all-margins specific constructor.
071: */
072: public void testConstructorSpecific() {
073: Insets insets = new Insets(PX_1, PX_2, PX_3, PX_4);
074: assertEquals(insets.getLeft(), PX_1);
075: assertEquals(insets.getTop(), PX_2);
076: assertEquals(insets.getRight(), PX_3);
077: assertEquals(insets.getBottom(), PX_4);
078: }
079:
080: /**
081: * Test integer/pixel all-margins equal constructor.
082: */
083: public void testConstructorPixelEqual() {
084: Insets insets = new Insets(1);
085: assertEquals(insets.getLeft(), PX_1);
086: assertEquals(insets.getTop(), PX_1);
087: assertEquals(insets.getRight(), PX_1);
088: assertEquals(insets.getBottom(), PX_1);
089: }
090:
091: /**
092: * Test integer/pixel horizontal = vertical constructor.
093: */
094: public void testConstructorPixelHV() {
095: Insets insets = new Insets(1, 2);
096: assertEquals(insets.getLeft(), PX_1);
097: assertEquals(insets.getTop(), PX_2);
098: assertEquals(insets.getRight(), PX_1);
099: 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(
121: null, null, null, null));
122: assertFalse(new Insets(1, 2, 3, 4)
123: .equals(new Insets(1, 2, 3, 5)));
124: assertFalse(new Insets(1, 2, 3, 4)
125: .equals(new Insets(1, 2, 5, 4)));
126: assertFalse(new Insets(1, 2, 3, 4)
127: .equals(new Insets(1, 5, 3, 4)));
128: assertFalse(new Insets(1, 2, 3, 4)
129: .equals(new Insets(5, 2, 3, 4)));
130: assertTrue(new Insets(PX_1, PX_2, PX_3, PX_4)
131: .equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
132: assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4)
133: .equals(new Insets(null, PX_2, PX_3, PX_4)));
134: assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4)
135: .equals(new Insets(PX_1, null, PX_3, PX_4)));
136: assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4)
137: .equals(new Insets(PX_1, PX_2, null, PX_4)));
138: assertFalse(new Insets(PX_1, PX_2, PX_3, PX_4)
139: .equals(new Insets(PX_1, PX_2, PX_3, null)));
140: assertFalse(new Insets(null, PX_2, PX_3, PX_4)
141: .equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
142: assertFalse(new Insets(PX_1, null, PX_3, PX_4)
143: .equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
144: assertFalse(new Insets(PX_1, PX_2, null, PX_4)
145: .equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
146: assertFalse(new Insets(PX_1, PX_2, PX_3, null)
147: .equals(new Insets(PX_1, PX_2, PX_3, PX_4)));
148: }
149: }
|