Tutorials
Swing TestingA freshly constructed SaveAsDialog should be in a known state, and we need to check the things we listed at the start of this chapter.
Let's now look at the noteworthy parts of this code.
Note 1: In accordance with the rules for GrandTestAuto (see Chapter 19), the test is a public method, returns a boolean, and has name ending with "Test". As with all of the tests, we begin with the init() method that creates and shows the dialog. After the body of the test, we call cleanup() and return true. If problems are found, they cause an assert exception.
Note 2: The UI Wrapper gives us the dialog, and from this we can check the title. It is important that we are using the UI class to get the title of the dialog in a thread-safe manner.
Note 3: Here we are checking the size of dialog is reasonable. The actual allowed upper and lower bounds on height and width were found simply by trial and error.
Note 4: Although the UI Wrapper gives us access to the name field and the buttons, we must not interrogate them directly. Rather, we use our UI methods to investigate them in a thread-safe manner.