Skip to content

Commit 64be5d2

Browse files
committed
BatchModeTest: show UI on EDT
Otherwise this can lead to deadlocks. See #306
1 parent 915bec8 commit 64be5d2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/test/java/net/imagej/legacy/BatchModeTest.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
import org.scijava.plugin.Plugin;
4747
import org.scijava.ui.UIService;
4848

49-
import java.awt.GraphicsEnvironment;
49+
import java.awt.*;
50+
import java.lang.reflect.InvocationTargetException;
5051

5152
import static org.junit.Assert.assertArrayEquals;
5253
import static org.junit.Assume.assumeFalse;
@@ -110,7 +111,18 @@ private void showLegacyUI() {
110111
// TODO: This should be improved. The test should also work in headless mode, without the legacy ui visible.
111112
assumeFalse(GraphicsEnvironment.isHeadless());
112113
UIService service = context.service(UIService.class);
113-
service.showUI();
114+
Runnable showUI = new Runnable() {
115+
@Override
116+
public void run() {
117+
service.showUI();
118+
}
119+
};
120+
try {
121+
EventQueue.invokeAndWait(showUI);
122+
}
123+
catch (InterruptedException | InvocationTargetException e) {
124+
throw new RuntimeException(e);
125+
}
114126
}
115127

116128
/** Simple command that outputs a {@link Dataset}. Used for testing. */

0 commit comments

Comments
 (0)