Class ExecutableInvoker
- java.lang.Object
-
- org.junit.jupiter.engine.execution.ExecutableInvoker
-
@API(status=INTERNAL, since="5.0") public class ExecutableInvoker extends java.lang.Object
ExecutableInvoker
encapsulates the invocation of aExecutable
(i.e., method or constructor), including support for dynamic resolution of method parameters viaParameterResolvers
.- Since:
- 5.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ExecutableInvoker.ReflectiveInterceptorCall<E extends java.lang.reflect.Executable,T>
-
Field Summary
Fields Modifier and Type Field Description private static InvocationInterceptorChain
interceptorChain
private static Logger
logger
-
Constructor Summary
Constructors Constructor Description ExecutableInvoker()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
asLabel(java.lang.reflect.Executable executable)
<T> T
invoke(java.lang.reflect.Constructor<T> constructor, java.util.Optional<java.lang.Object> outerInstance, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<java.lang.reflect.Constructor<T>,T> interceptorCall)
Invoke the supplied constructor with the supplied outer instance and dynamic parameter resolution.<T> T
invoke(java.lang.reflect.Method method, java.lang.Object target, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<java.lang.reflect.Method,T> interceptorCall)
Invoke the suppliedstatic
method with dynamic parameter resolution.private <E extends java.lang.reflect.Executable,T>
Tinvoke(InvocationInterceptor.Invocation<T> originalInvocation, ReflectiveInvocationContext<E> invocationContext, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<E,T> call)
private java.lang.Object
resolveParameter(ParameterContext parameterContext, java.lang.reflect.Executable executable, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry)
private java.lang.Object[]
resolveParameters(java.lang.reflect.Executable executable, java.util.Optional<java.lang.Object> target, java.util.Optional<java.lang.Object> outerInstance, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry)
Resolve the array of parameters for the supplied executable, target, and outer instance.private java.lang.Object[]
resolveParameters(java.lang.reflect.Method method, java.util.Optional<java.lang.Object> target, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry)
Resolve the array of parameters for the supplied method and target.private void
validateResolvedType(java.lang.reflect.Parameter parameter, java.lang.Object value, java.lang.reflect.Executable executable, ParameterResolver resolver)
-
-
-
Field Detail
-
logger
private static final Logger logger
-
interceptorChain
private static final InvocationInterceptorChain interceptorChain
-
-
Method Detail
-
invoke
public <T> T invoke(java.lang.reflect.Constructor<T> constructor, java.util.Optional<java.lang.Object> outerInstance, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<java.lang.reflect.Constructor<T>,T> interceptorCall)
Invoke the supplied constructor with the supplied outer instance and dynamic parameter resolution.This method should only be used to invoke the constructor for an inner class.
- Parameters:
constructor
- the constructor to invoke and resolve parameters forouterInstance
- the outer instance to supply as the first argument to the constructor; empty, for top-level classesextensionContext
- the currentExtensionContext
extensionRegistry
- theExtensionRegistry
to retrieveParameterResolvers
frominterceptorCall
- the call for intercepting this constructor invocation via all registered interceptors
-
invoke
public <T> T invoke(java.lang.reflect.Method method, java.lang.Object target, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<java.lang.reflect.Method,T> interceptorCall)
Invoke the suppliedstatic
method with dynamic parameter resolution.- Parameters:
method
- the method to invoke and resolve parameters forextensionContext
- the currentExtensionContext
extensionRegistry
- theExtensionRegistry
to retrieveParameterResolvers
frominterceptorCall
- the call for intercepting this method invocation via all registered interceptors
-
invoke
private <E extends java.lang.reflect.Executable,T> T invoke(InvocationInterceptor.Invocation<T> originalInvocation, ReflectiveInvocationContext<E> invocationContext, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<E,T> call)
-
resolveParameters
private java.lang.Object[] resolveParameters(java.lang.reflect.Method method, java.util.Optional<java.lang.Object> target, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry)
Resolve the array of parameters for the supplied method and target.- Parameters:
method
- the method for which to resolve parameterstarget
- anOptional
containing the target on which the executable will be invoked; nevernull
but should be empty for static methods and constructorsextensionContext
- the currentExtensionContext
extensionRegistry
- theExtensionRegistry
to retrieveParameterResolvers
from- Returns:
- the array of Objects to be used as parameters in the executable
invocation; never
null
though potentially empty
-
resolveParameters
private java.lang.Object[] resolveParameters(java.lang.reflect.Executable executable, java.util.Optional<java.lang.Object> target, java.util.Optional<java.lang.Object> outerInstance, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry)
Resolve the array of parameters for the supplied executable, target, and outer instance.- Parameters:
executable
- the executable for which to resolve parameterstarget
- anOptional
containing the target on which the executable will be invoked; nevernull
but should be empty for static methods and constructorsouterInstance
- the outer instance that will be supplied as the first argument to a constructor for an inner class; should benull
for methods and constructors for top-level or static classesextensionContext
- the currentExtensionContext
extensionRegistry
- theExtensionRegistry
to retrieveParameterResolvers
from- Returns:
- the array of Objects to be used as parameters in the executable
invocation; never
null
though potentially empty
-
resolveParameter
private java.lang.Object resolveParameter(ParameterContext parameterContext, java.lang.reflect.Executable executable, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry)
-
validateResolvedType
private void validateResolvedType(java.lang.reflect.Parameter parameter, java.lang.Object value, java.lang.reflect.Executable executable, ParameterResolver resolver)
-
asLabel
private static java.lang.String asLabel(java.lang.reflect.Executable executable)
-
-