Class ExecutableInvoker
java.lang.Object
org.junit.jupiter.engine.execution.ExecutableInvoker
ExecutableInvoker
encapsulates the invocation of a
Executable
(i.e., method or constructor),
including support for dynamic resolution of method parameters via
ParameterResolvers
.- Since:
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final InvocationInterceptorChain
private static final Logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
asLabel
(Executable executable) <T> T
invoke
(Constructor<T> constructor, Optional<Object> outerInstance, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<Constructor<T>, T> interceptorCall) Invoke the supplied constructor with the supplied outer instance and dynamic parameter resolution.<T> T
invoke
(Method method, Object target, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<Method, T> interceptorCall) Invoke the suppliedstatic
method with dynamic parameter resolution.private <E extends Executable,
T>
Tinvoke
(InvocationInterceptor.Invocation<T> originalInvocation, ReflectiveInvocationContext<E> invocationContext, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<E, T> call) private Object
resolveParameter
(ParameterContext parameterContext, Executable executable, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) private Object[]
resolveParameters
(Executable executable, Optional<Object> target, Optional<Object> outerInstance, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) Resolve the array of parameters for the supplied executable, target, and outer instance.private Object[]
resolveParameters
(Method method, Optional<Object> target, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) Resolve the array of parameters for the supplied method and target.private void
validateResolvedType
(Parameter parameter, Object value, Executable executable, ParameterResolver resolver)
-
Field Details
-
logger
-
interceptorChain
-
-
Constructor Details
-
ExecutableInvoker
public ExecutableInvoker()
-
-
Method Details
-
invoke
public <T> T invoke(Constructor<T> constructor, Optional<Object> outerInstance, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<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(Method method, Object target, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<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 Executable,T> T invoke(InvocationInterceptor.Invocation<T> originalInvocation, ReflectiveInvocationContext<E> invocationContext, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry, ExecutableInvoker.ReflectiveInterceptorCall<E, T> call) -
resolveParameters
private Object[] resolveParameters(Method method, Optional<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 Object[] resolveParameters(Executable executable, Optional<Object> target, Optional<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 Object resolveParameter(ParameterContext parameterContext, Executable executable, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) -
validateResolvedType
private void validateResolvedType(Parameter parameter, Object value, Executable executable, ParameterResolver resolver) -
asLabel
-