/**
* Expect a button action with action id on executing button mnemonic.
* @param pMnemonic to execute on button throwing event
* @param pAntiMnemonic to execute on button not throwing event
* @param pActionId expected to be thrown by button
* @param pIndex of button in container
*/
public void testButtonActionByMnemonic() {
JButton button = get(dialog, JButton.class, 0); // button finden
assertNotNull("No button found on index 0", button);
int keyEvent = KeyStroke.getAWTKeyStroke("B",
KeyEvent.ALT_DOWN_MASK).getKeyCode();
helper.sendKeyAction(new KeyEventData(this, button, keyEvent));
verify(); // check ob button action <--- no action thrown
}
}
The test works with enterClickAndLeave, but not with mnemonic sendString.
Maybe someone knows the answer.
Cheers
Per
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi *,
maybe someone can turn my light on, how i could test button mnemonic. I tried the following
public class MyPanel extends JPanel {
public MyPanel() {
super();
JButton b = new JButton("Ok with B");
b.setMnemonic("B");
add(b);
}
}
public class MyPanelTest extends JFCTestCase {
private JFCTestHelper helper = null;
private JDialog dialog = null;
private MyPanel testee = null;
/**
* Constructor of MyPanelTest.
*/
public MyPanelTest() {
super();
}
/**
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
helper = new JFCTestHelper();
testee = new MyPanel();
dialog = new JDialog();
dialog.setContentPane(testee);
dialog.setVisible(true);
}
/**
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
dialog.dispose();
testee = null;
dialog = null;
helper = null;
flushAWT();
JFCTestHelper.cleanUp(this);
}
/**
* Expect a button action with action id on executing button mnemonic.
* @param pMnemonic to execute on button throwing event
* @param pAntiMnemonic to execute on button not throwing event
* @param pActionId expected to be thrown by button
* @param pIndex of button in container
*/
public void testButtonActionByMnemonic() {
JButton button = get(dialog, JButton.class, 0); // button finden
assertNotNull("No button found on index 0", button);
int keyEvent = KeyStroke.getAWTKeyStroke("B",
KeyEvent.ALT_DOWN_MASK).getKeyCode();
helper.sendKeyAction(new KeyEventData(this, button, keyEvent));
verify(); // check ob button action <--- no action thrown
}
}
The test works with enterClickAndLeave, but not with mnemonic sendString.
Maybe someone knows the answer.
Cheers
Per