title: How do simulate a button click in a swing pop up dialog?
body: <p>I'm new to Java, I want to write a JUnit test for a name validate class</p>
  
  <p>I want to test the following code:</p>
  
  <pre><code>public boolean createNewUMLClassFromString(String className) {
      if(validate(className)){
                ....
      }
      return false;
  }
  
  private boolean validate(String userInput){
      /* check if it's empty  */
      if (userInput.equals("")){  
                      JOptionPane.showMessageDialog(null, "Class Name can't be empty");
          return false;
      }
              return true;
  }
  </code></pre>
  
  <p>So I wrote a JUnit</p>
  
  <pre><code>public void emptyStringCheckerTest(){
      assertFalse("new class can not be empty", um.createNewUMLClassFromString("do"));
  
  }
  </code></pre>
  
  <p>it works, but in the test running process, I need to click the pop up dialog every time.</p>
  
  <p>So Is anyone can tell me how to simulate a button click in the test process, or Is there a better way to write the test? Thanks?</p>