StudioProgressRunner implements ProgressRunner { @Override public void runSyncWithProgress(@NotNull final ProgressRunnable progressRunnable) { UIUtil.invokeAndWaitIfNeeded((Runnable)() -> { Task task = new Task.Modal(myProject, myProgressTitle, myCancellable) { @Override public void run(@NotNull ProgressIndicator indicator) { doRunSync(indicator, progressRunnable); } }; ProgressManager.getInstance().run(task); }); } StudioProgressRunner(boolean modal,
                              boolean cancellable,
                              String progressTitle,
                              @Nullable Project project); @Override void runAsyncWithProgress(@NotNull final ProgressRunnable r); @VisibleForTesting void runAsyncWithProgress(@NotNull final ProgressRunnable r, boolean overrideTestMode); @Override void runSyncWithProgress(@NotNull final ProgressRunnable progressRunnable); @Override void runSyncWithoutProgress(@NotNull Runnable r);  }
@Test public void testSyncWithProgressNonUi() throws Exception { StudioProgressRunner runner = new StudioProgressRunner(true, false, "test", null); AtomicBoolean invoked = new AtomicBoolean(false); ProgressRunner.ProgressRunnable runnable = (indicator, runner1) -> { assertFalse(ApplicationManager.getApplication().isDispatchThread()); try { Thread.sleep(100); } catch (InterruptedException e) { fail(); } invoked.set(true); }; runner.runSyncWithProgress(runnable); assertTrue(invoked.get()); }
@Test public void testSyncFromNonUi() throws Exception { Future f = ApplicationManager.getApplication().executeOnPooledThread(() -> { StudioProgressRunner runner = new StudioProgressRunner(true, false, "test", null); AtomicBoolean invoked = new AtomicBoolean(false); ProgressRunner.ProgressRunnable runnable = (indicator, runner1) -> { assertFalse(ApplicationManager.getApplication().isDispatchThread()); try { Thread.sleep(100); } catch (InterruptedException e) { fail(); } invoked.set(true); }; runner.runSyncWithProgress(runnable); assertTrue(invoked.get()); }); FutureUtils.pumpEventsAndWaitForFuture(f, 10, TimeUnit.SECONDS); }