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 Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing;
21:
22: import java.awt.event.ActionEvent;
23: import java.awt.event.ActionListener;
24: import junit.framework.TestCase;
25:
26: public class JComboBoxRTest extends TestCase {
27: private boolean eventFired;
28:
29: public void testJComboBox() throws Exception {
30: new JComboBox();
31: }
32:
33: public void testRemoveAllItems() throws Exception {
34: JComboBox cb = new JComboBox(new String[] { "1", "2", "4" });
35: assertEquals(3, cb.getItemCount());
36: cb.removeAllItems();
37: assertEquals(0, cb.getItemCount());
38: cb.addItem("new");
39: assertEquals(1, cb.getItemCount());
40: }
41:
42: public void testKeyboardActionsEnabled() throws Exception {
43: JComboBox cb = new JComboBox(new String[] { "1", "2", "4" });
44: checkActionState(cb, "hidePopup", false);
45: checkActionState(cb, "enterPressed", true);
46: checkActionState(cb, "selectPrevious", true);
47: checkActionState(cb, "togglePopup", true);
48: checkActionState(cb, "spacePopup", true);
49: }
50:
51: private void checkActionState(final JComboBox cb,
52: final String actionName, final boolean expectedState) {
53: Action action = cb.getActionMap().get(actionName);
54: assertNotNull(action);
55: assertEquals(expectedState, action.isEnabled());
56: }
57:
58: public void testSetSelectedItem() {
59: // regression test HARMONY-1533
60: String item = "item";
61: JComboBox jcb = new JComboBox(new String[] { item });
62: jcb.addActionListener(new ActionListener() {
63: public void actionPerformed(ActionEvent ae) {
64: eventFired = true;
65: }
66: });
67: jcb.setSelectedItem(item);
68: assertTrue("action performed", eventFired);
69: }
70: }
|