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 Alexander T. Simbirtsev
019: * @version $Revision$
020: * Created on 29.11.2004
021:
022: */package javax.swing.border;
023:
024: import java.awt.Insets;
025: import javax.swing.JPanel;
026: import javax.swing.SwingTestCase;
027:
028: public class EmptyBorderTest extends SwingTestCase {
029: public void testIsBorderOpaque() {
030: EmptyBorder border = new EmptyBorder(0, 1, 2, 3);
031: assertFalse("EmptyBorder is not opaque ", border
032: .isBorderOpaque());
033: }
034:
035: /*
036: * Class under test for void EmptyBorder(Insets)
037: */
038: public void testEmptyBorderInsets() {
039: int top = 100;
040: int left = 200;
041: int right = 300;
042: int bottom = 400;
043: EmptyBorder border = new EmptyBorder(new Insets(top, left,
044: bottom, right));
045: assertEquals(border.getBorderInsets(), new Insets(top, left,
046: bottom, right));
047: }
048:
049: /*
050: * Class under test for void EmptyBorder(int, int, int, int)
051: */
052: public void testEmptyBorderintintintint() {
053: int top = 100;
054: int left = 200;
055: int right = 300;
056: int bottom = 400;
057: EmptyBorder border = new EmptyBorder(top, left, bottom, right);
058: assertEquals(border.getBorderInsets(), new Insets(top, left,
059: bottom, right));
060: }
061:
062: /*
063: * Class under test for void EmptyBorder(int, int)
064: */
065: public void testEmptyBorderintint() {
066: if (!isHarmony()) {
067: return;
068: }
069: int top = 111;
070: int bottom = 111;
071: int left = 345;
072: int right = 345;
073: EmptyBorder border = new EmptyBorder(top, left);
074: assertEquals(border.getBorderInsets(), new Insets(top, left,
075: bottom, right));
076: }
077:
078: /*
079: * Class under test for Insets getBorderInsets(Component, Insets)
080: */
081: public void testGetBorderInsetsComponentInsets() {
082: int top = 100;
083: int left = 200;
084: int right = 300;
085: int bottom = 400;
086: EmptyBorder border = new EmptyBorder(top, left, bottom, right);
087: Insets insets = new Insets(1, 1, 1, 1);
088: JPanel panel = new JPanel();
089: panel.setBorder(new EmptyBorder(1, 1, 1, 1));
090: border.getBorderInsets(panel, insets);
091: assertEquals("insets values coinside", top, insets.top);
092: assertEquals("insets values coinside", left, insets.left);
093: assertEquals("insets values coinside", right, insets.right);
094: assertEquals("insets values coinside", bottom, insets.bottom);
095: insets = new Insets(1, 1, 1, 1);
096: panel.setBorder(null);
097: Insets newInsets = border.getBorderInsets(panel, insets);
098: assertEquals("insets values coinside", top, newInsets.top);
099: assertEquals("insets values coinside", left, newInsets.left);
100: assertEquals("insets values coinside", right, newInsets.right);
101: assertEquals("insets values coinside", bottom, newInsets.bottom);
102: assertEquals("insets values coinside", top, insets.top);
103: assertEquals("insets values coinside", left, insets.left);
104: assertEquals("insets values coinside", right, insets.right);
105: assertEquals("insets values coinside", bottom, insets.bottom);
106: }
107:
108: /*
109: * Class under test for Insets getBorderInsets(Component)
110: */
111: public void testGetBorderInsetsComponent() {
112: int top = 100;
113: int left = 200;
114: int right = 300;
115: int bottom = 400;
116: EmptyBorder border = new EmptyBorder(top, left, bottom, right);
117: Insets insets = null;
118: JPanel panel = new JPanel();
119: panel.setBorder(new EmptyBorder(1, 1, 1, 1));
120: insets = border.getBorderInsets(panel);
121: assertEquals("insets values coinside", top, insets.top);
122: assertEquals("insets values coinside", left, insets.left);
123: assertEquals("insets values coinside", right, insets.right);
124: assertEquals("insets values coinside", bottom, insets.bottom);
125: panel.setBorder(null);
126: insets = border.getBorderInsets(panel);
127: assertEquals("insets values coinside", top, insets.top);
128: assertEquals("insets values coinside", left, insets.left);
129: assertEquals("insets values coinside", right, insets.right);
130: assertEquals("insets values coinside", bottom, insets.bottom);
131: }
132:
133: /*
134: * Class under test for void paintBorder(Component, Graphics, int, int, int, int)
135: *
136: * since this method doesn't suppose to do anything,
137: * i think the good decision is to leave this testcase empty
138: */
139: public void testPaintBorderComponentGraphicsintintintint() {
140: }
141:
142: /*
143: * Class under test for Insets getBorderInsets()
144: */
145: public void testGetBorderInsets() {
146: int top = 100;
147: int left = 200;
148: int right = 300;
149: int bottom = 400;
150: EmptyBorder border = new EmptyBorder(top, left, bottom, right);
151: Insets insets = border.getBorderInsets();
152: assertEquals("insets values coinside", top, insets.top);
153: assertEquals("insets values coinside", left, insets.left);
154: assertEquals("insets values coinside", right, insets.right);
155: assertEquals("insets values coinside", bottom, insets.bottom);
156: }
157:
158: public void testReadWriteObject() throws Exception {
159: EmptyBorder border1 = new EmptyBorder(10, 20, 30, 40);
160: EmptyBorder border2 = new EmptyBorder(40, 50, 60, 70);
161: EmptyBorder resurrectedBorder = (EmptyBorder) serializeObject(border1);
162: assertNotNull(resurrectedBorder);
163: assertEquals("Deserialized values coinsides", resurrectedBorder
164: .getBorderInsets(), border1.getBorderInsets());
165: resurrectedBorder = (EmptyBorder) serializeObject(border2);
166: assertNotNull(resurrectedBorder);
167: assertEquals("Deserialized values coinsides", resurrectedBorder
168: .getBorderInsets(), border2.getBorderInsets());
169: }
170: }
|