Testing DialogWrappers

I have a custom ExitDialog class that extends com.intellij.openapi.ui.DialogWrapper:

public class ExitDialog extends DialogWrapper {



I'd like to write a unit testf or it. For example,


  @Test
  public void testContinueButton() {
    DialogWrapperPeer peer = dialog.getPeer();
    Container contentPane = peer.getContentPane();

    JButton continueButton = findButtonWithText(contentPane, "Continue");
    Assume.assumeNotNull(continueButton);

    Assert.assertEquals("Continue", continueButton.getText());
  }


  @Nullable
  private JButton findButtonWithText(Component component, String text) {
    if (component instanceof JButton) {
      JButton button = (JButton) component;
      if (text.equals(button.getText())) {
        return button;
      }
    } else if (component instanceof Container) {
      Container container = (Container) component;
      for (Component child : container.getComponents()) {
        JButton button = findButtonWithText(child, text);
        if (button != null) {
          return button;
        }
      }
    }
    return null;
  }
}


This test passes when run from inside IDEA. However when I run it from the command line, findButtonWithText returns null. That is, it cannot locate the relevant button.

At first I thought that maybe it had to do with an AWT headless vs. non-headless environment, but it appears that IDEA is also running this test in headles mode.

Can anyone surmise why this test might pass inside IDEA and fail outside of it?

https://github.com/GoogleCloudPlatform/gcloud-intellij/pull/217

for more context if you want to see thw whole thing.

Please sign in to leave a comment.