@API(status=STABLE, since="5.0") public interface ParameterResolver extends Extension
ParameterResolver
defines the API for Extensions
that wish to dynamically resolve arguments for parameters
at runtime.
If a constructor for a test class or a
@Test
,
@BeforeEach
,
@AfterEach
,
@BeforeAll
, or
@AfterAll
method declares a parameter,
an argument for the parameter must be resolved at runtime by a
ParameterResolver
.
Implementations must provide a no-args constructor.
Modifier and Type | Method and Description |
---|---|
Object |
resolveParameter(ParameterContext parameterContext,
ExtensionContext extensionContext)
Resolve an argument for the
Parameter in the supplied ParameterContext
for the supplied ExtensionContext . |
boolean |
supportsParameter(ParameterContext parameterContext,
ExtensionContext extensionContext)
Determine if this resolver supports resolution of an argument for the
Parameter in the supplied ParameterContext for the supplied
ExtensionContext . |
boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException
Parameter
in the supplied ParameterContext
for the supplied
ExtensionContext
.
The Method
or Constructor
in which the parameter is declared can be retrieved via
ParameterContext.getDeclaringExecutable()
.
parameterContext
- the context for the parameter for which an argument should
be resolved; never null
extensionContext
- the extension context for the Executable
about to be invoked; never null
true
if this resolver can resolve an argument for the parameterParameterResolutionException
resolveParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,
ParameterContext
Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException
Parameter
in the supplied ParameterContext
for the supplied ExtensionContext
.
This method is only called by the framework if supportsParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
previously returned true
for the same ParameterContext
and ExtensionContext
.
The Method
or Constructor
in which the parameter is declared can be retrieved via
ParameterContext.getDeclaringExecutable()
.
parameterContext
- the context for the parameter for which an argument should
be resolved; never null
extensionContext
- the extension context for the Executable
about to be invoked; never null
null
if the
parameter type is not a primitiveParameterResolutionException
supportsParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,
ParameterContext