Skip to content

Commit

Permalink
BatchModeTest: show UI on EDT
Browse files Browse the repository at this point in the history
Otherwise this can lead to deadlocks.

See #306
  • Loading branch information
hinerm committed Jul 19, 2024
1 parent 915bec8 commit 64be5d2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/test/java/net/imagej/legacy/BatchModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 64be5d2

Please sign in to comment.