Skip to content

Commit 700c2d4

Browse files
committed
Hide implementation details
1 parent 872146d commit 700c2d4

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed

junit-platform-launcher/src/main/java/org/junit/platform/launcher/LauncherInterceptor.java

-39
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
package org.junit.platform.launcher;
1212

1313
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
14-
import static org.apiguardian.api.API.Status.INTERNAL;
15-
16-
import java.util.List;
1714

1815
import org.apiguardian.api.API;
1916

@@ -58,18 +55,6 @@
5855
@API(status = EXPERIMENTAL, since = "1.10")
5956
public interface LauncherInterceptor {
6057

61-
LauncherInterceptor NOOP = new LauncherInterceptor() {
62-
@Override
63-
public <T> T intercept(Invocation<T> invocation) {
64-
return invocation.proceed();
65-
}
66-
67-
@Override
68-
public void close() {
69-
// do nothing
70-
}
71-
};
72-
7358
/**
7459
* Intercept the supplied invocation.
7560
*
@@ -97,28 +82,4 @@ interface Invocation<T> {
9782
T proceed();
9883
}
9984

100-
@API(status = INTERNAL, since = "1.10")
101-
static LauncherInterceptor composite(List<LauncherInterceptor> interceptors) {
102-
if (interceptors.isEmpty()) {
103-
return NOOP;
104-
}
105-
return interceptors.stream() //
106-
.skip(1) //
107-
.reduce(interceptors.get(0), (a, b) -> new LauncherInterceptor() {
108-
@Override
109-
public void close() {
110-
try {
111-
a.close();
112-
}
113-
finally {
114-
b.close();
115-
}
116-
}
117-
118-
@Override
119-
public <T> T intercept(Invocation<T> invocation) {
120-
return a.intercept(() -> b.intercept(invocation));
121-
}
122-
});
123-
}
12485
}

junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/DefaultLauncherSession.java

+38-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,27 @@
2828
*/
2929
class DefaultLauncherSession implements LauncherSession {
3030

31+
private static final LauncherInterceptor NOOP_INTERCEPTOR = new LauncherInterceptor() {
32+
@Override
33+
public <T> T intercept(Invocation<T> invocation) {
34+
return invocation.proceed();
35+
}
36+
37+
@Override
38+
public void close() {
39+
// do nothing
40+
}
41+
};
42+
3143
private final LauncherInterceptor interceptor;
3244
private final LauncherSessionListener listener;
3345
private final DelegatingLauncher launcher;
3446

3547
DefaultLauncherSession(List<LauncherInterceptor> interceptors, Supplier<LauncherSessionListener> listenerSupplier,
3648
Supplier<Launcher> launcherSupplier) {
37-
interceptor = LauncherInterceptor.composite(interceptors);
49+
interceptor = composite(interceptors);
3850
Launcher launcher;
39-
if (interceptor == LauncherInterceptor.NOOP) {
51+
if (interceptor == NOOP_INTERCEPTOR) {
4052
this.listener = listenerSupplier.get();
4153
launcher = launcherSupplier.get();
4254
}
@@ -98,4 +110,28 @@ public void execute(TestPlan testPlan, TestExecutionListener... listeners) {
98110
throw new PreconditionViolationException("Launcher session has already been closed");
99111
}
100112
}
113+
114+
private static LauncherInterceptor composite(List<LauncherInterceptor> interceptors) {
115+
if (interceptors.isEmpty()) {
116+
return NOOP_INTERCEPTOR;
117+
}
118+
return interceptors.stream() //
119+
.skip(1) //
120+
.reduce(interceptors.get(0), (a, b) -> new LauncherInterceptor() {
121+
@Override
122+
public void close() {
123+
try {
124+
a.close();
125+
}
126+
finally {
127+
b.close();
128+
}
129+
}
130+
131+
@Override
132+
public <T> T intercept(Invocation<T> invocation) {
133+
return a.intercept(() -> b.intercept(invocation));
134+
}
135+
});
136+
}
101137
}

0 commit comments

Comments
 (0)