Tutorials
Swing TestingSince SaveAsDialog.show() blocks, we cannot call this from our main thread; instead we spawn a new thread. This thread could just be an anonymous inner class in the init()method:
The problem with this approach is that it does not allow us to investigate the state of the Thread that called the show() method. We want to write tests that check that this thread is blocked while the dialog is showing.
Our solution is a simple inner class:
The method of most interest here is isAwakened(), which waits for up to one second for the awake flag to have been set. This uses a class, Waiting, that is discussed in Chapter 12. We'll look at tests that use this isAwakened() method later on. Another point of interest is that we've given our new thread a name (by the call super("Shower") in the constructor). It's really useful to give each thread we create a name, for reasons that will be discussed in Chapter 20.