void (Test test, TestResult testResult) { if (test instanceof TestCase) { if ("warning".equals(((TestCase)test).getName())) { return; } var testResultDelegate = new TestResultDelegate(testResult); var failureExposingListener = new RetryListener(); testResultDelegate.addFirstListener(failureExposingListener); retryTest(test.toString(), () -> { synchronized (testResultDelegate) { failureExposingListener.throwable = null; } test.run(testResultDelegate); synchronized (testResultDelegate) { if (failureExposingListener.throwable != null) { throw failureExposingListener.throwable; } } }); testResultDelegate.removeListener(failureExposingListener); } else if (!(test instanceof TestAll) && !(test instanceof TestSuite) && !(test instanceof TestDecorator) && !(test instanceof JUnit4TestAdapter) && !(test instanceof JUnit4TestCaseFacade)) { var msg = "Unable to retry test " + test.getClass().getCanonicalName(); //noinspection UseOfSystemOutOrSystemErr System.out.println("##teamcity[message text='" + msg + "' status='ERROR']"); throw new IllegalStateException(msg); } }