Last active
August 29, 2015 14:05
-
-
Save donat/f697ed27e4af5f03779a to your computer and use it in GitHub Desktop.
Eclipse: wait in UI unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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