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 Vadim L. Bogdanov
019: * @version $Revision$
020: */package javax.swing;
021:
022: import java.awt.Container;
023: import java.awt.Component;
024:
025: public class InternalFrameFocusTraversalPolicyTest extends
026: SwingTestCase {
027: /*
028: * InternalFrameFocusTraversalPolicy is an abstract class.
029: * This class implements its abstract methods.
030: */
031: private class TestInternalFrameFocusTraversalPolicy extends
032: InternalFrameFocusTraversalPolicy {
033: @Override
034: public Component getComponentAfter(final Container aContainer,
035: final Component aComponent) {
036: return null;
037: }
038:
039: @Override
040: public Component getComponentBefore(final Container aContainer,
041: final Component aComponent) {
042: return null;
043: }
044:
045: @Override
046: public Component getFirstComponent(final Container aContainer) {
047: return null;
048: }
049:
050: @Override
051: public Component getLastComponent(final Container aContainer) {
052: return null;
053: }
054:
055: @Override
056: public Component getDefaultComponent(final Container aContainer) {
057: if (aContainer == null) {
058: throw new IllegalArgumentException();
059: }
060: return mostRecentFocusOwner;
061: }
062: }
063:
064: private TestInternalFrameFocusTraversalPolicy policy;
065:
066: JInternalFrame frame;
067:
068: JPanel mostRecentFocusOwner;
069:
070: /*
071: * @see TestCase#setUp()
072: */
073: @Override
074: protected void setUp() throws Exception {
075: super .setUp();
076: policy = new TestInternalFrameFocusTraversalPolicy();
077: frame = new JInternalFrame();
078: }
079:
080: /*
081: * @see TestCase#tearDown()
082: */
083: @Override
084: protected void tearDown() throws Exception {
085: super .tearDown();
086: }
087:
088: /*
089: *
090: */
091: public InternalFrameFocusTraversalPolicyTest(final String name) {
092: super (name);
093: }
094:
095: /*
096: * Class under test for InternalFrameFocusTraversalPolicy()
097: */
098: public void testInternalFrameFocusTraversalPolicy() {
099: // nothing to test
100: }
101:
102: /*
103: * Class under test for Component getInitialComponent(JInternalFrame)
104: */
105: public void testGetInitialComponent() {
106: // no components in the frame, shold return null
107: assertNull("null", policy.getInitialComponent(frame));
108: // test with 'null' parameter
109: boolean ok = false;
110: try {
111: policy.getInitialComponent((JInternalFrame) null);
112: } catch (IllegalArgumentException e) {
113: ok = true;
114: } finally {
115: assertTrue("exception", ok);
116: }
117: // there are components
118: mostRecentFocusOwner = new JPanel();
119: frame.getContentPane().add(mostRecentFocusOwner);
120: assertTrue("mostRecentFocusOwner", policy
121: .getInitialComponent(frame) == mostRecentFocusOwner);
122: }
123: }
|