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 30.11.2004
021:
022: */package javax.swing.border;
023:
024: import java.awt.Color;
025: import java.awt.Insets;
026: import javax.swing.JPanel;
027: import javax.swing.SwingTestCase;
028:
029: public class LineBorderTest extends SwingTestCase {
030: public static void main(final String[] args) {
031: junit.textui.TestRunner.run(LineBorderTest.class);
032: }
033:
034: /*
035: * Class under test for Insets getBorderInsets(Component, Insets)
036: */
037: public void testGetBorderInsetsComponentInsets() {
038: int thickness1 = 11;
039: int thickness2 = 22;
040: int thickness3 = 33;
041: int thickness4 = 44;
042: LineBorder border = new LineBorder(Color.black, thickness1);
043: Insets insets = new Insets(1, 1, 1, 1);
044: JPanel panel = new JPanel();
045: panel.setBorder(new LineBorder(Color.black, thickness2));
046: border.getBorderInsets(panel, insets);
047: assertEquals("insets values coinside", thickness1, insets.top);
048: assertEquals("insets values coinside", thickness1, insets.left);
049: assertEquals("insets values coinside", thickness1, insets.right);
050: assertEquals("insets values coinside", thickness1,
051: insets.bottom);
052: insets = new Insets(thickness3, thickness3, thickness3,
053: thickness3);
054: panel.setBorder(new LineBorder(Color.black, thickness4));
055: Insets newInsets = border.getBorderInsets(panel, insets);
056: assertEquals("insets values coinside", thickness1,
057: newInsets.top);
058: assertEquals("insets values coinside", thickness1,
059: newInsets.left);
060: assertEquals("insets values coinside", thickness1,
061: newInsets.right);
062: assertEquals("insets values coinside", thickness1,
063: newInsets.bottom);
064: assertEquals("insets values coinside", thickness1, insets.top);
065: assertEquals("insets values coinside", thickness1, insets.left);
066: assertEquals("insets values coinside", thickness1, insets.right);
067: assertEquals("insets values coinside", thickness1,
068: insets.bottom);
069: }
070:
071: /*
072: * Class under test for Insets getBorderInsets(Component)
073: */
074: public void testGetBorderInsetsComponent() {
075: int thickness = 11;
076: LineBorder border = new LineBorder(Color.black, thickness);
077: Insets insets = null;
078: JPanel panel = new JPanel();
079: panel.setBorder(new LineBorder(Color.white));
080: insets = border.getBorderInsets(panel);
081: assertEquals("insets values coinside", thickness, insets.top);
082: assertEquals("insets values coinside", thickness, insets.left);
083: assertEquals("insets values coinside", thickness, insets.right);
084: assertEquals("insets values coinside", thickness, insets.bottom);
085: panel.setBorder(null);
086: insets = border.getBorderInsets(panel);
087: assertEquals("insets values coinside", thickness, insets.top);
088: assertEquals("insets values coinside", thickness, insets.left);
089: assertEquals("insets values coinside", thickness, insets.right);
090: assertEquals("insets values coinside", thickness, insets.bottom);
091: }
092:
093: public void testPaintBorder() {
094: // JPanel panel = new JPanel();
095: //
096: // panel.setBorder(new LineBorder(Color.red, 10, true));
097: // JFrame frame = new JFrame();
098: // frame.getContentPane().add(panel);
099: // panel.setPreferredSize(new Dimension(100, 50));
100: // frame.pack();
101: // frame.show();
102: // while(!frame.isActive());
103: // while(frame.isActive());
104: }
105:
106: public void testIsBorderOpaque() {
107: LineBorder border1 = new LineBorder(Color.black);
108: LineBorder border2 = new LineBorder(Color.black, 11, true);
109: LineBorder border3 = new LineBorder(Color.black, 13, false);
110: assertTrue("LineBorder is opaque ", border1.isBorderOpaque());
111: assertFalse("LineBorder with round corners is not opaque ",
112: border2.isBorderOpaque());
113: assertTrue("LineBorder is opaque ", border3.isBorderOpaque());
114: }
115:
116: /*
117: * Class under test for void LineBorder(Color, int, boolean)
118: */
119: public void testLineBorderColorintboolean() {
120: int thickness = 11;
121: boolean roundedCorners = true;
122: Color color = Color.yellow;
123: LineBorder border = new LineBorder(color, thickness,
124: roundedCorners);
125: assertEquals("Thickness coinsides", thickness, border
126: .getThickness());
127: assertEquals("RoundedCorners coinsides", roundedCorners, border
128: .getRoundedCorners());
129: assertEquals("Colors coinsides", color, border.getLineColor());
130: thickness = 23;
131: roundedCorners = false;
132: color = Color.red;
133: border = new LineBorder(color, thickness, roundedCorners);
134: assertEquals("Thickness coinsides", thickness, border
135: .getThickness());
136: assertEquals("RoundedCorners coinsides", roundedCorners, border
137: .getRoundedCorners());
138: assertEquals("Colors coinsides", color, border.getLineColor());
139: thickness = 37;
140: roundedCorners = true;
141: color = Color.cyan;
142: border = new LineBorder(color, thickness, roundedCorners);
143: assertEquals("Thickness coinsides", thickness, border
144: .getThickness());
145: assertEquals("RoundedCorners coinsides", roundedCorners, border
146: .getRoundedCorners());
147: assertEquals("Colors coinsides", color, border.getLineColor());
148: }
149:
150: /*
151: * Class under test for void LineBorder(Color, int)
152: */
153: public void testLineBorderColorint() {
154: int thickness = 11;
155: boolean roundedCorners = false;
156: Color color = Color.yellow;
157: LineBorder border = new LineBorder(color, thickness);
158: assertEquals("Thickness coinsides", thickness, border
159: .getThickness());
160: assertEquals("RoundedCorners coinsides", roundedCorners, border
161: .getRoundedCorners());
162: assertEquals("Colors coinsides", color, border.getLineColor());
163: thickness = 23;
164: color = Color.red;
165: border = new LineBorder(color, thickness);
166: assertEquals("Thickness coinsides", thickness, border
167: .getThickness());
168: assertEquals("RoundedCorners coinsides", roundedCorners, border
169: .getRoundedCorners());
170: assertEquals("Colors coinsides", color, border.getLineColor());
171: thickness = 37;
172: color = Color.cyan;
173: border = new LineBorder(color, thickness);
174: assertEquals("Thickness coinsides", thickness, border
175: .getThickness());
176: assertEquals("RoundedCorners coinsides", roundedCorners, border
177: .getRoundedCorners());
178: assertEquals("Colors coinsides", color, border.getLineColor());
179: }
180:
181: /*
182: * Class under test for void LineBorder(Color)
183: */
184: public void testLineBorderColor() {
185: int thickness = 1;
186: boolean roundedCorners = false;
187: Color color = Color.yellow;
188: LineBorder border = new LineBorder(color);
189: assertEquals("Thickness coinsides", thickness, border
190: .getThickness());
191: assertEquals("RoundedCorners coinsides", roundedCorners, border
192: .getRoundedCorners());
193: assertEquals("Colors coinsides", color, border.getLineColor());
194: color = Color.red;
195: border = new LineBorder(color);
196: assertEquals("Thickness coinsides", thickness, border
197: .getThickness());
198: assertEquals("RoundedCorners coinsides", roundedCorners, border
199: .getRoundedCorners());
200: assertEquals("Colors coinsides", color, border.getLineColor());
201: color = Color.cyan;
202: border = new LineBorder(color);
203: assertEquals("Thickness coinsides", thickness, border
204: .getThickness());
205: assertEquals("RoundedCorners coinsides", roundedCorners, border
206: .getRoundedCorners());
207: assertEquals("Colors coinsides", color, border.getLineColor());
208: }
209:
210: public void testGetLineColor() {
211: Color color = Color.yellow;
212: LineBorder border = new LineBorder(color, 1, true);
213: assertEquals("Colors coinsides", color, border.getLineColor());
214: color = Color.red;
215: border = new LineBorder(color, 10, false);
216: assertEquals("Colors coinsides", color, border.getLineColor());
217: color = Color.cyan;
218: border = new LineBorder(color, 110);
219: assertEquals("Colors coinsides", color, border.getLineColor());
220: }
221:
222: public void testGetRoundedCorners() {
223: boolean roundedCorners = true;
224: LineBorder border = new LineBorder(Color.black, 1,
225: roundedCorners);
226: assertEquals("RoundedCorners coinsides", roundedCorners, border
227: .getRoundedCorners());
228: roundedCorners = false;
229: border = new LineBorder(Color.black, 2, roundedCorners);
230: assertEquals("RoundedCorners coinsides", roundedCorners, border
231: .getRoundedCorners());
232: border = new LineBorder(Color.black, 1);
233: assertEquals("RoundedCorners coinsides", roundedCorners, border
234: .getRoundedCorners());
235: }
236:
237: public void testGetThickness() {
238: int thickness = 11;
239: LineBorder border = new LineBorder(Color.black, thickness);
240: assertEquals("Thickness coinsides", thickness, border
241: .getThickness());
242: thickness = 23;
243: border = new LineBorder(Color.black, thickness, true);
244: assertEquals("Thickness coinsides", thickness, border
245: .getThickness());
246: thickness = 37;
247: border = new LineBorder(Color.black, thickness, false);
248: assertEquals("Thickness coinsides", thickness, border
249: .getThickness());
250: }
251:
252: public void testCreateGrayLineBorder() {
253: LineBorder border = (LineBorder) LineBorder
254: .createGrayLineBorder();
255: assertEquals("Thickness coinsides", 1, border.getThickness());
256: assertFalse("RoundedCorners coinsides", border
257: .getRoundedCorners());
258: assertEquals("Colors coinsides", Color.gray, border
259: .getLineColor());
260: }
261:
262: public void testCreateBlackLineBorder() {
263: LineBorder border = (LineBorder) LineBorder
264: .createBlackLineBorder();
265: assertEquals("Thickness coinsides", 1, border.getThickness());
266: assertFalse("RoundedCorners coinsides", border
267: .getRoundedCorners());
268: assertEquals("Colors coinsides", Color.black, border
269: .getLineColor());
270: }
271:
272: public void testReadWriteObject() throws Exception {
273: LineBorder border1 = new LineBorder(Color.red, 33, false);
274: LineBorder border2 = new LineBorder(Color.yellow, 47, true);
275: LineBorder resurrectedBorder = (LineBorder) serializeObject(border1);
276: assertNotNull(resurrectedBorder);
277: assertEquals("Deserialized values coinsides", resurrectedBorder
278: .getThickness(), border1.getThickness());
279: assertEquals("Deserialized values coinsides", resurrectedBorder
280: .getLineColor(), border1.getLineColor());
281: assertEquals("Deserialized values coinsides", resurrectedBorder
282: .getRoundedCorners(), border1.getRoundedCorners());
283: resurrectedBorder = (LineBorder) serializeObject(border2);
284: assertNotNull(resurrectedBorder);
285: assertEquals("Deserialized values coinsides", resurrectedBorder
286: .getThickness(), border2.getThickness());
287: assertEquals("Deserialized values coinsides", resurrectedBorder
288: .getLineColor(), border2.getLineColor());
289: assertEquals("Deserialized values coinsides", resurrectedBorder
290: .getRoundedCorners(), border2.getRoundedCorners());
291: }
292: }
|