Skip to content

Instantly share code, notes, and snippets.

@donat
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donat/f697ed27e4af5f03779a to your computer and use it in GitHub Desktop.
Save donat/f697ed27e4af5f03779a to your computer and use it in GitHub Desktop.
Eclipse: wait in UI unit test
private void delay(long waitTimeMillis) {
Display display = Display.getCurrent();
// if UI thread then process input
if (display != null) {
long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
while (System.currentTimeMillis() < endTimeMillis) {
if (!display.readAndDispatch())
display.sleep();
}
display.update();
}
// otherwise just wait for the delay
else {
try {
Thread.sleep(waitTimeMillis);
} catch (InterruptedException e) {
// do nothing
}
}
}
// wait for jobs to finish
public void waitForJobs() {
while (Job.getJobManager().currentJob() != null) {
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment