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 01.10.2004
021:
022: */package javax.swing;
023:
024: import java.io.IOException;
025:
026: public class ComponentInputMapTest extends InputMapTest {
027: protected JComponent component = null;
028:
029: public static void main(final String[] args) {
030: junit.textui.TestRunner.run(ComponentInputMapTest.class);
031: }
032:
033: /*
034: * @see TestCase#setUp()
035: */
036: @Override
037: protected void setUp() throws Exception {
038: super .setUp();
039: component = new JPanel();
040: map = new ComponentInputMap(component);
041: parent = new ComponentInputMap(component);
042: }
043:
044: @Override
045: public void testSetGetParent() {
046: parent = new ComponentInputMap(component);
047: map.setParent(parent);
048: testExceptionalCase(new IllegalArgumentCase() {
049: @Override
050: public void exceptionalAction() throws Exception {
051: map.setParent(new InputMap());
052: }
053: });
054: testExceptionalCase(new IllegalArgumentCase() {
055: @Override
056: public void exceptionalAction() throws Exception {
057: map.setParent(new ComponentInputMap(new JPanel()));
058: }
059: });
060: map.setParent(null);
061: assertNull(map.getParent());
062: }
063:
064: public void testComponentInputMap() {
065: boolean thrown = false;
066: try {
067: map = new ComponentInputMap(component);
068: } catch (IllegalArgumentException e) {
069: thrown = true;
070: }
071: assertFalse(thrown);
072: component = null;
073: try {
074: map = new ComponentInputMap(component);
075: } catch (IllegalArgumentException e) {
076: thrown = true;
077: }
078: assertTrue(thrown);
079: }
080:
081: public void testGetComponent() {
082: assertTrue(((ComponentInputMap) map).getComponent() == component);
083: }
084:
085: @Override
086: public void testWriteObject() throws IOException {
087: //super.testWriteObject();
088: }
089:
090: @Override
091: public void testReadObject() {
092: /*
093: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(KeyEvent.VK_1, 0);
094: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(KeyEvent.VK_2, 0);
095: Object object1 = "object1";
096: Object object2 = "object2";
097: ComponentInputMap parent = new ComponentInputMap(component);
098: map.setParent(parent);
099: map.put(keyStroke1, object1);
100: map.put(keyStroke2, object2);
101: try {
102: FileOutputStream fo = new FileOutputStream("tmp");
103: ObjectOutputStream so = new ObjectOutputStream(fo);
104: so.writeObject(map);
105: so.flush();
106: } catch (Exception e) {
107: assertFalse(true);
108: }
109: try {
110: FileInputStream fi = new FileInputStream("tmp");
111: ObjectInputStream si = new ObjectInputStream(fi);
112: ComponentInputMap ressurectedMap = (ComponentInputMap)si.readObject();
113: assertTrue(ressurectedMap.getParent() != null);
114: assertTrue(ressurectedMap.getComponent() != null);
115: assertTrue(ressurectedMap.get(keyStroke1).equals(object1));
116: assertTrue(ressurectedMap.get(keyStroke2).equals(object2));
117: } catch (Exception e) {
118: System.out.println(e);
119: assertFalse(true);
120: }
121: */
122: }
123: }
|