public void testProcessKeyEvent() throws Exception {
comboBox.setKeySelectionManager(null);
createVisibleComboBox();
PopupMenuController pmc = new PopupMenuController();
comboBox.addPopupMenuListener(pmc);
KeyEvent event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_A);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_TAB);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
comboBox.setPopupVisible(true);
assertNotNull(pmc.getEvent());
assertEquals(PopupMenuController.VISIBLE, pmc.getEventType());
pmc.reset();
comboBox.addItem("a");
comboBox.addItem("b");
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_A);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
assertEquals("a", comboBox.getSelectedItem());
pmc.reset();
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_B);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
assertEquals("b", comboBox.getSelectedItem());
pmc.reset();
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_A);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
assertEquals("a", comboBox.getSelectedItem());
pmc.reset();
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_TAB);
comboBox.processKeyEvent(event);
assertNotNull(pmc.getEvent());
assertEquals(PopupMenuController.INVISIBLE, pmc.getEventType());
assertEquals("a", comboBox.getSelectedItem());
comboBox.setKeySelectionManager(new JComboBox.KeySelectionManager() {
public int selectionForKey(final char key, final ComboBoxModel model) {
return -1;
}
});
pmc.reset();
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_TAB);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
assertEquals("a", comboBox.getSelectedItem());
pmc.reset();
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_A);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
assertEquals("a", comboBox.getSelectedItem());
pmc.reset();
event = new KeyEvent(comboBox, KeyEvent.KEY_PRESSED, EventQueue
.getMostRecentEventTime(), 0, KeyEvent.VK_B);
comboBox.processKeyEvent(event);
assertNull(pmc.getEvent());
assertEquals("a", comboBox.getSelectedItem());
}