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 Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import junit.framework.TestCase;
023:
024: /**
025: * LabelTest
026: */
027: public class LabelTest extends TestCase {
028: Label label;
029:
030: /*
031: * @see TestCase#setUp()
032: */
033: @Override
034: protected void setUp() throws Exception {
035: super .setUp();
036: label = new Label();
037: }
038:
039: /*
040: * @see TestCase#tearDown()
041: */
042: @Override
043: protected void tearDown() throws Exception {
044: super .tearDown();
045: }
046:
047: /*
048: * Class under test for void Label(java.lang.String)
049: */
050: public final void testLabelString() {
051: label = new Label(null);
052: assertEquals(Label.LEFT, label.getAlignment());
053: assertNull(label.getText());
054: String text = "label text";
055: label = new Label(text);
056: assertEquals(text, label.getText());
057: }
058:
059: /*
060: * Class under test for void Label()
061: */
062: public final void testLabel() {
063: assertEquals("", label.getText());
064: assertEquals(Label.LEFT, label.getAlignment());
065: }
066:
067: /*
068: * Class under test for void Label(java.lang.String, int)
069: */
070: public final void testLabelStringint() {
071: boolean iaeCaught = false;
072: try {
073: label = new Label(null, 100);
074: } catch (IllegalArgumentException iae) {
075: iaeCaught = true;
076: }
077: assertTrue(iaeCaught);
078: int align = Label.RIGHT;
079: String text = "label";
080: label = new Label(text, align);
081: assertEquals(align, label.getAlignment());
082: assertEquals(text, label.getText());
083: }
084:
085: public final void testGetAlignment() {
086: assertEquals(Label.LEFT, label.getAlignment());
087: }
088:
089: public final void testGetText() {
090: assertEquals("", label.getText());
091: }
092:
093: public final void testSetAlignment() {
094: boolean iaeCaught = false;
095: try {
096: label.setAlignment(-1);
097: } catch (IllegalArgumentException iae) {
098: iaeCaught = true;
099: }
100: assertTrue(iaeCaught);
101: int align = Label.CENTER;
102: label.setAlignment(align);
103: assertEquals(align, label.getAlignment());
104: }
105:
106: public final void testSetText() {
107: label.setText(null);
108: assertNull(label.getText());
109: String text = "";
110: label.setText(text);
111: assertEquals(text, label.getText());
112: }
113:
114: public void testDeadLoop4887() {
115: final int count[] = new int[1];
116: Component c = new Label() {
117: public void paint(Graphics g) {
118: count[0]++;
119: setEnabled(true);
120: }
121: };
122:
123: Tools.checkDeadLoop(c, count);
124: }
125:
126: }
|