From dd67bf55b3086d2073de960d38c4d16531cda97c Mon Sep 17 00:00:00 2001 From: hinerm Date: Fri, 19 Jul 2024 14:26:55 -0500 Subject: [PATCH] BatchModeTest: show UI on EDT Otherwise this can lead to deadlocks. See https://github.com/imagej/imagej-legacy/issues/306 --- .../java/net/imagej/legacy/BatchModeTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/imagej/legacy/BatchModeTest.java b/src/test/java/net/imagej/legacy/BatchModeTest.java index 362573a2..5c282009 100644 --- a/src/test/java/net/imagej/legacy/BatchModeTest.java +++ b/src/test/java/net/imagej/legacy/BatchModeTest.java @@ -46,7 +46,8 @@ import org.scijava.plugin.Plugin; import org.scijava.ui.UIService; -import java.awt.GraphicsEnvironment; +import java.awt.*; +import java.lang.reflect.InvocationTargetException; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assume.assumeFalse; @@ -110,7 +111,18 @@ private void showLegacyUI() { // TODO: This should be improved. The test should also work in headless mode, without the legacy ui visible. assumeFalse(GraphicsEnvironment.isHeadless()); UIService service = context.service(UIService.class); - service.showUI(); + Runnable showUI = new Runnable() { + @Override + public void run() { + service.showUI(); + } + }; + try { + EventQueue.invokeAndWait(showUI); + } + catch (InterruptedException | InvocationTargetException e) { + throw new RuntimeException(e); + } } /** Simple command that outputs a {@link Dataset}. Used for testing. */