title: How do I activate JButton ActionListener inside code (unit testing purposes)?
body: <p>I need to activate a JButton ActionListener within a JDialog so I can do some unit testing  using JUnit.</p>
  
  <p>Basically I have this:</p>
  
  <pre><code>    public class MyDialog extends JDialog {
      public static int APPLY_OPTION= 1;
      protected int buttonpressed;
      protected JButton okButton;
      public MyDialog(Frame f) {
          super(f);
          okButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  buttonpressed= APPLY_OPTION;
              }
          } );
      public int getButtonPressed() {
          return buttonpressed;
      }
  
  }
  </code></pre>
  
  <p>then I have my JUnit file:</p>
  
  <pre><code>public class testMyDialog {
  
      @Test
      public void testGetButtonPressed() {
          MyDialog fc= new MyDialog(null);
          fc.okButton.???????? //how do I activate the ActionListener?
          assertEquals(MyDialog.APPLY_OPTION, fc.getButtonPressed());
      }
  }
  </code></pre>
  
  <p>This may sound redundant to do in a unit test, but the actual class is a lot more complicated than that...</p>