Package org.junit.platform.launcher
Interface LauncherInterceptor
-
- All Known Implementing Classes:
ClasspathAlignmentCheckingLauncherInterceptor
@API(status=MAINTAINED, since="1.13.3") public interface LauncherInterceptorInterceptor for test discovery and execution by aLauncherin the context of aLauncherSession.Interceptors are instantiated once per
LauncherSessionand closed after the session is closed. They can intercept the following invocations:-
creation of
LauncherSessionListenerinstances registered via theServiceLoadermechanism -
creation of
Launcherinstances -
calls to
Launcher.discover(LauncherDiscoveryRequest),Launcher.execute(TestPlan, TestExecutionListener...), andLauncher.execute(LauncherDiscoveryRequest, TestExecutionListener...)
Implementations of this interface can be registered via the
ServiceLoadermechanism by additionally setting the "junit.platform.launcher.interceptors.enabled" configuration parameter totrue.A typical use case is to create a custom
ClassLoaderin the constructor of the implementing class, replace thecontextClassLoaderof the current thread whileinterceptinginvocations, and close the customClassLoaderinclose()- Since:
- 1.10
- See Also:
Launcher,LauncherSession,LauncherConstants.ENABLE_LAUNCHER_INTERCEPTORS
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceLauncherInterceptor.Invocation<T>An invocation that can be intercepted.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Closes this interceptor.<T> Tintercept(LauncherInterceptor.Invocation<T> invocation)Intercept the supplied invocation.
-
-
-
Method Detail
-
intercept
<T> T intercept(LauncherInterceptor.Invocation<T> invocation)
Intercept the supplied invocation.Implementations must call
LauncherInterceptor.Invocation.proceed()exactly once.- Parameters:
invocation- the intercepted invocation; nevernull- Returns:
- the result of the invocation
-
close
void close()
Closes this interceptor.Any resources held by this interceptor should be released by this method.
-
-