3

I'm writing some functional tests for a Swing app with UISpec4j.

There are some fields to fill in, and a button for saving. Depending on the combination of fields filled in, there might be a modal error dialog displayed when the save button is clicked.

I don't want to duplicate the logic for showing the error dialog in my test cases, just assert that the error dialog did not show when clicking the save button.

Can this be done in a less convoluted way than calling WindowInterceptor.getModalDialog() and catching AssertionError?

Per
  • 636
  • 5
  • 8

1 Answers1

0

Depending on how your code is organized in the application, you may include Mockito or equivalent and check that the method in charge of displaying the dialog is never called. From the Mockito API ("Making sure interaction(s) never happened on mock") you can add something like:

//verify that method was never called on a mock
verify(mockOne, never()).add("two");

Another approach would be to replace the dialog class with your own wrapper and check that the show method never gets called.

Daniel H.
  • 1,782
  • 16
  • 18