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 java.awt.Rectangle;
026: import javax.swing.JPanel;
027: import javax.swing.SwingTestCase;
028:
029: public class AbstractBorderTest extends SwingTestCase {
030: /*
031: * Class under test for Insets getBorderInsets(Component, Insets)
032: */
033: public void testGetBorderInsetsComponentInsets() {
034: AbstractBorder border = new AbstractBorder() {
035: private static final long serialVersionUID = 1L;
036: };
037: Insets insets = new Insets(1, 1, 1, 1);
038: JPanel panel = new JPanel();
039: panel.setBorder(new EmptyBorder(1, 1, 1, 1));
040: border.getBorderInsets(panel, insets);
041: assertEquals("insets values coinside", 0, insets.top);
042: assertEquals("insets values coinside", 0, insets.left);
043: assertEquals("insets values coinside", 0, insets.right);
044: assertEquals("insets values coinside", 0, insets.bottom);
045: insets = new Insets(1, 1, 1, 1);
046: panel.setBorder(new EmptyBorder(10, 10, 10, 10));
047: Insets newInsets = border.getBorderInsets(panel, insets);
048: assertEquals("insets values coinside", 0, newInsets.top);
049: assertEquals("insets values coinside", 0, newInsets.left);
050: assertEquals("insets values coinside", 0, newInsets.right);
051: assertEquals("insets values coinside", 0, newInsets.bottom);
052: assertEquals("insets values coinside", 0, insets.top);
053: assertEquals("insets values coinside", 0, insets.left);
054: assertEquals("insets values coinside", 0, insets.right);
055: assertEquals("insets values coinside", 0, insets.bottom);
056: }
057:
058: /*
059: * Class under test for Insets getBorderInsets(Component)
060: */
061: public void testGetBorderInsetsComponent() {
062: AbstractBorder border = new AbstractBorder() {
063: private static final long serialVersionUID = 1L;
064: };
065: Insets insets = null;
066: JPanel panel = new JPanel();
067: panel.setBorder(new EmptyBorder(1, 1, 1, 1));
068: insets = border.getBorderInsets(panel);
069: assertEquals("insets values coinside", 0, insets.top);
070: assertEquals("insets values coinside", 0, insets.left);
071: assertEquals("insets values coinside", 0, insets.right);
072: assertEquals("insets values coinside", 0, insets.bottom);
073: panel.setBorder(null);
074: insets = border.getBorderInsets(panel);
075: assertEquals("insets values coinside", 0, insets.top);
076: assertEquals("insets values coinside", 0, insets.left);
077: assertEquals("insets values coinside", 0, insets.right);
078: assertEquals("insets values coinside", 0, insets.bottom);
079: }
080:
081: /*
082: * Class under test for void paintBorder(Component, Graphics, int, int, int, int)
083: *
084: * since this method doesn't suppose to do anything,
085: * i think the good decision is to leave this testcase empty
086: */
087: public void testPaintBorder() {
088: }
089:
090: public void testIsBorderOpaque() {
091: AbstractBorder border = new AbstractBorder() {
092: private static final long serialVersionUID = 1L;
093: };
094: assertFalse("AbstractBorder is not opaque ", border
095: .isBorderOpaque());
096: }
097:
098: /*
099: * Class under test for Rectangle getInteriorRectangle(Component, int, int, int, int)
100: */
101: public void testGetInteriorRectangleComponentintintintint() {
102: int top = 10;
103: int left = 20;
104: int right = 30;
105: int bottom = 40;
106: int x = 100;
107: int y = 200;
108: int width = 300;
109: int height = 400;
110: AbstractBorder border = new AbstractBorder() {
111: private static final long serialVersionUID = 1L;
112: };
113: JPanel panel = new JPanel();
114: panel.setBorder(new EmptyBorder(top, left, bottom, right));
115: Rectangle rect = border.getInteriorRectangle(panel, x, y,
116: width, height);
117: assertEquals(new Rectangle(x, y, width, height), rect);
118: rect = border.getInteriorRectangle(null, x, y, width, height);
119: assertEquals(new Rectangle(x, y, width, height), rect);
120: border = new EmptyBorder(top, left, bottom, right);
121: rect = border.getInteriorRectangle(null, x, y, width, height);
122: assertEquals(new Rectangle(x + left, y + top, width - left
123: - right, height - top - bottom), rect);
124: }
125:
126: /*
127: * Class under test for Rectangle getInteriorRectangle(Component, Border, int, int, int, int)
128: */
129: public void testGetInteriorRectangleComponentBorderintintintint() {
130: int top = 10;
131: int left = 20;
132: int right = 30;
133: int bottom = 40;
134: int x = 100;
135: int y = 200;
136: int width = 300;
137: int height = 400;
138:
139: JPanel panel = new JPanel();
140: panel.setBorder(new EmptyBorder(top, left, bottom, right));
141: Rectangle rect = AbstractBorder.getInteriorRectangle(panel,
142: new EmptyBorder(0, 0, 0, 0), x, y, width, height);
143: assertEquals(new Rectangle(x, y, width, height), rect);
144: rect = AbstractBorder.getInteriorRectangle(null,
145: new EmptyBorder(0, 0, 0, 0), x, y, width, height);
146: assertEquals(new Rectangle(x, y, width, height), rect);
147: rect = AbstractBorder.getInteriorRectangle(panel,
148: new EmptyBorder(top, left, bottom, right), x, y, width,
149: height);
150: assertEquals(new Rectangle(x + left, y + top, width - left
151: - right, height - top - bottom), rect);
152: rect = AbstractBorder.getInteriorRectangle(null,
153: new EmptyBorder(top, left, bottom, right), x, y, width,
154: height);
155: assertEquals(new Rectangle(x + left, y + top, width - left
156: - right, height - top - bottom), rect);
157: rect = AbstractBorder.getInteriorRectangle(panel, null, x, y,
158: width, height);
159: assertEquals(new Rectangle(x, y, width, height), rect);
160: rect = AbstractBorder.getInteriorRectangle(null, null, x, y,
161: width, height);
162: assertEquals(new Rectangle(x, y, width, height), rect);
163: }
164: }
|