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.*;
23:
24: import junit.framework.TestCase;
25:
26: @SuppressWarnings("serial")
27: public class MenuTest extends TestCase {
28: public void testAddRemove() {
29: Component comp = new Component() {
30: };
31: // create topmost menu
32: PopupMenu popup = new PopupMenu();
33: comp.add(popup);
34: assertTrue(popup.getParent() == comp);
35:
36: // create submenu
37: Menu menu = new Menu("Menu");
38: popup.add(menu);
39: assertEquals(popup, menu.getParent());
40: assertEquals(1, popup.getItemCount());
41:
42: // add item to submenu
43: MenuItem item = new MenuItem("Item");
44: menu.add(item);
45: assertEquals(menu, item.getParent());
46: assertEquals(1, menu.getItemCount());
47:
48: // move item from submenu to topmost menu
49: popup.add(item);
50: assertEquals(popup, item.getParent());
51: assertEquals(0, menu.getItemCount());
52: assertEquals(2, popup.getItemCount());
53:
54: // remove submenu from topmost menu
55: popup.remove(menu);
56: assertEquals(1, popup.getItemCount());
57:
58: // remove item from topmost menu
59: popup.remove(item);
60: assertEquals(0, popup.getItemCount());
61: }
62:
63: public void testAddRemoveListener() {
64: MenuItem item = new MenuItem("Item");
65: ActionListener listener = new ActionListener() {
66: public void actionPerformed(ActionEvent e) {
67: }
68: };
69: item.addActionListener(listener);
70: assertNotNull(item.getActionListeners());
71: assertEquals(1, item.getActionListeners().length);
72: assertEquals(listener, item.getActionListeners()[0]);
73: }
74: }
|