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,

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

    JButton continueButton = findButtonWithText(contentPane, "Continue");

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

  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?


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

Please sign in to leave a comment.