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: package java.awt;
018:
019: import javax.swing.DebugGraphics;
020: import javax.swing.JButton;
021:
022: import junit.framework.TestCase;
023:
024: public class ContainerRTest extends TestCase {
025:
026: public final void testRemoveComponent() {
027: // Regression test for HARMONY-1476
028: try {
029: new Container().remove((Component) null);
030: fail("NPE was not thrown");
031: } catch (NullPointerException ex) {
032: // passed
033: }
034: }
035:
036: public final void testSetFocusTraversalKeys() {
037: try {
038: Button btn = new Button();
039: btn
040: .setFocusTraversalKeys(
041: KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,
042: new Container()
043: .getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
044: fail("IllegalArgumentException expected");
045: } catch (IllegalArgumentException e) {
046: }
047: }
048:
049: @SuppressWarnings("serial")
050: public final void testAddNotify() {
051: Container c1 = new Container() {
052: };
053: Container c2 = new Container() {
054: };
055: assertFalse(c1.isDisplayable());
056: assertFalse(c2.isDisplayable());
057:
058: c1.add(c2);
059: c1.addNotify();
060:
061: assertTrue(c1.isDisplayable());
062: assertTrue(c2.isDisplayable());
063: }
064:
065: public final void testPaint() {
066: // Regression test for HARMONY-2527
067: final Component c = new Frame();
068: c.paint(c.getGraphics());
069: // End of regression for HARMONY-2527
070:
071: // Regression for HARMONY-3443
072: final Graphics g;
073: final Frame f = new Frame();
074:
075: f.add(new JButton());
076: f.setVisible(true);
077: g = f.getGraphics();
078:
079: try {
080: g.setClip(null);
081: assertNull(g.getClip());
082: f.paint(g);
083: } finally {
084: f.dispose();
085: }
086: // End of regression for HARMONY-3443
087:
088: // Regression for HARMONY-3430
089: new Container().paint(new DebugGraphics());
090: // End of regression for HARMONY-3430
091: }
092:
093: public void testAddComponent() {
094: try {
095: Container s = new Container();
096: s.add((Component) null);
097: fail("NPE should be thrown");
098: } catch (NullPointerException npe) {
099: // PASSED
100: }
101: }
102:
103: // regression for HARMONY-2443
104: public void testPaintComponentsImpl() {
105: ScrollPane scp = new ScrollPane();
106:
107: scp.printComponents((Graphics) null);
108: }
109:
110: }
|