01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Pavel Dolgov
19: * @version $Revision$
20: */package java.awt;
21:
22: import java.awt.event.KeyEvent;
23:
24: import junit.framework.TestCase;
25:
26: /**
27: * MenuShortcutTest
28: */
29:
30: public class MenuShortcutTest extends TestCase {
31:
32: public static void main(String[] args) {
33: junit.textui.TestRunner.run(MenuShortcutTest.class);
34: }
35:
36: public void testMenuShortcut() {
37: MenuShortcut s = new MenuShortcut(KeyEvent.VK_SPACE);
38: MenuShortcut t = new MenuShortcut(KeyEvent.VK_T, true);
39: MenuShortcut u = new MenuShortcut(KeyEvent.VK_U, false);
40:
41: assertEquals(KeyEvent.VK_SPACE, s.getKey());
42: assertFalse(s.usesShiftModifier());
43: assertEquals("Ctrl+Space", s.toString());
44: assertEquals("key=32", s.paramString());
45:
46: assertEquals(KeyEvent.VK_T, t.getKey());
47: assertTrue(t.usesShiftModifier());
48: assertEquals("Ctrl+Shift+T", t.toString());
49: assertEquals("key=84,usesShiftModifier", t.paramString());
50:
51: assertEquals(KeyEvent.VK_U, u.getKey());
52: assertFalse(u.usesShiftModifier());
53: assertEquals("Ctrl+U", u.toString());
54: assertEquals("key=85", u.paramString());
55:
56: assertTrue(s.equals(new MenuShortcut(KeyEvent.VK_SPACE)));
57: assertFalse(s.equals(new MenuShortcut(KeyEvent.VK_SPACE, true)));
58: assertFalse(s.equals(new MenuShortcut(KeyEvent.VK_ENTER)));
59: assertFalse(s.equals("Ctrl+Space"));
60: assertFalse(s.equals(null));
61: assertFalse(s.equals(t));
62:
63: assertTrue(new MenuShortcut(KeyEvent.VK_T, true).equals(t));
64: assertFalse(new MenuShortcut(KeyEvent.VK_U, true).equals(u));
65:
66: assertEquals(new MenuShortcut(KeyEvent.VK_T, true).hashCode(),
67: t.hashCode());
68: assertFalse(new MenuShortcut(KeyEvent.VK_U, true).hashCode() == u
69: .hashCode());
70: }
71:
72: }
|