void (LauncherSession session) { // Method could be called several times, don't override field if (listener == null) { listener = OutOfProcessRetries.getListenerForOutOfProcessRetry(); } if (listener == null) { return; } session.getLauncher().registerTestExecutionListeners(new TestExecutionListener() { @Override public void testPlanExecutionStarted(TestPlan testPlan) { suiteStarted = System.nanoTime(); } @Override public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { final TestExecutionResult.Status status = testExecutionResult.getStatus(); final Throwable throwable = testExecutionResult.getThrowable().orElse(null); if (status != TestExecutionResult.Status.FAILED) { return; } testIdentifier.getSource().map( testSource -> testSource instanceof MethodSource ms ? ms.getClassName() : testSource instanceof ClassSource cs ? cs.getClassName() : null ).ifPresent(className -> listener.addError(className, throwable)); } }); }