I'm trying to write some GUI and integration tests using JUnit and FEST. Here is what I have:
@Before
public void setUp(){
try{
program.main(args);
robot.wait(30000); //gives IllegalMonitorStateException
Thread.sleep(30000); //no Exception occurs here
} catch (Exception e){
e.printStackTrace();
}
}
robot
and args
are already initialized.
Why do I get such an exception when I call wait
? Why I don't get the same exception when I call sleep
?
You're calling Object.wait()
- which is not the same as Thread.sleep()
. In particular:
wait()
requires that you already own the monitor on the object you call it onwait()
allows the thread to be notified (via Object.notify
/notifyAll
) and wake up early; Thread.sleep()
would require the thread to be interrupted.