From 700c2d4f25b48bfc4970f99d3198af5e8c5e3f37 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Tue, 31 Jan 2023 15:49:28 +0100 Subject: [PATCH] Hide implementation details --- .../launcher/LauncherInterceptor.java | 39 ------------------ .../launcher/core/DefaultLauncherSession.java | 40 ++++++++++++++++++- 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/LauncherInterceptor.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/LauncherInterceptor.java index 7f4c0e17c70f..262a1d539809 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/LauncherInterceptor.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/LauncherInterceptor.java @@ -11,9 +11,6 @@ package org.junit.platform.launcher; import static org.apiguardian.api.API.Status.EXPERIMENTAL; -import static org.apiguardian.api.API.Status.INTERNAL; - -import java.util.List; import org.apiguardian.api.API; @@ -58,18 +55,6 @@ @API(status = EXPERIMENTAL, since = "1.10") public interface LauncherInterceptor { - LauncherInterceptor NOOP = new LauncherInterceptor() { - @Override - public T intercept(Invocation invocation) { - return invocation.proceed(); - } - - @Override - public void close() { - // do nothing - } - }; - /** * Intercept the supplied invocation. * @@ -97,28 +82,4 @@ interface Invocation { T proceed(); } - @API(status = INTERNAL, since = "1.10") - static LauncherInterceptor composite(List interceptors) { - if (interceptors.isEmpty()) { - return NOOP; - } - return interceptors.stream() // - .skip(1) // - .reduce(interceptors.get(0), (a, b) -> new LauncherInterceptor() { - @Override - public void close() { - try { - a.close(); - } - finally { - b.close(); - } - } - - @Override - public T intercept(Invocation invocation) { - return a.intercept(() -> b.intercept(invocation)); - } - }); - } } diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/DefaultLauncherSession.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/DefaultLauncherSession.java index 42969448616e..b3743ac253a7 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/DefaultLauncherSession.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/DefaultLauncherSession.java @@ -28,15 +28,27 @@ */ class DefaultLauncherSession implements LauncherSession { + private static final LauncherInterceptor NOOP_INTERCEPTOR = new LauncherInterceptor() { + @Override + public T intercept(Invocation invocation) { + return invocation.proceed(); + } + + @Override + public void close() { + // do nothing + } + }; + private final LauncherInterceptor interceptor; private final LauncherSessionListener listener; private final DelegatingLauncher launcher; DefaultLauncherSession(List interceptors, Supplier listenerSupplier, Supplier launcherSupplier) { - interceptor = LauncherInterceptor.composite(interceptors); + interceptor = composite(interceptors); Launcher launcher; - if (interceptor == LauncherInterceptor.NOOP) { + if (interceptor == NOOP_INTERCEPTOR) { this.listener = listenerSupplier.get(); launcher = launcherSupplier.get(); } @@ -98,4 +110,28 @@ public void execute(TestPlan testPlan, TestExecutionListener... listeners) { throw new PreconditionViolationException("Launcher session has already been closed"); } } + + private static LauncherInterceptor composite(List interceptors) { + if (interceptors.isEmpty()) { + return NOOP_INTERCEPTOR; + } + return interceptors.stream() // + .skip(1) // + .reduce(interceptors.get(0), (a, b) -> new LauncherInterceptor() { + @Override + public void close() { + try { + a.close(); + } + finally { + b.close(); + } + } + + @Override + public T intercept(Invocation invocation) { + return a.intercept(() -> b.intercept(invocation)); + } + }); + } }