Reviews
Swing Extreme TestingSwing Extreme Testing - The init() Method
The init() Method
The job of the init() method is to create and show the SaveAsDialog instance so that it can be tested:
- private void init() {
- //Note 1
- names = new TreeSet<ikonname></ikonname>()
- names.add( new IkonName( "Albus" ) )
- names.add( new IkonName( "Minerva" ) )
- names.add( new IkonName( "Severus" ) )
- names.add( new IkonName( "Alastair" ) )
- //Note 2
- Runnable creator = new Runnable() {
- public void run() {
- frame = new JFrame( "SaveAsDialogTest" )
- frame.setVisible( true )
- sad = new SaveAsDialog( frame, names )
- }
- }
- UI.runInEventThread( creator )
- //Note 3
- //Start a thread to show the dialog (it is modal).
- shower = new ShowerThread()
- shower.start()
- //Note 4
- //Wait for the dialog to be showing.
- Waiting.waitFor( new Waiting.ItHappened() {
- public boolean itHappened() {
- return UI.findNamedFrame(
- SaveAsDialog.DIALOG_NAME ) != null
- }
- }, 1000 )
- //Note 5
- ui = new UISaveAsDialog()
- }
Now let's look at some of the key points in this code.
Note 1: In this block of code we create a set of IkonNames with which our SaveAsDialog can be created.
Note 2: It's convenient to create and show the owning frame and create the SaveAsDialog in a single Runnable. An alternative would be to create and show the frame with a UI call and use the Runnable just for creating the SaveAsDialog.
Note 3: Here we start our Shower, which will call the blocking show() method of SaveAsDialog from the event thread.
Note 4: Having called show() via the event dispatch thread from our Shower thread, we need to wait for the dialog to actually be showing on the screen. The way we do this is to search for a dialog that is on the screen and has the correct name.
Note 5: Once the SaveAsDialog is showing, we can create our UI Wrapper for it.
The cleanup() Method
The cleanup() method closes all frames in a thread-safe manner:
private void cleanup() { UI.disposeOfAllFrames(); }
The Unit Tests
We've now done all the hard work of building an infrastructure that will make our tests very simple to write. Let's now look at these tests.
Swing Extreme Testing
- Swing Extreme Testing
- Swing Extreme Testing - Outline of the Unit Test
- Swing Extreme Testing - Getting the Text of a Text Field
- Swing Extreme Testing - Unit Test Infrastructure
- Swing Extreme Testing - The ShowerThread Class
- Swing Extreme Testing - The init() Method
- Swing Extreme Testing - The Constructor Test
- Swing Extreme Testing - The wasCancelled() Test
- Swing Extreme Testing - The name() Test
- Swing Extreme Testing - The Data Validation Test







