- All Superinterfaces:
Extension
- All Known Implementing Classes:
TypeBasedParameterResolver
@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
.
Constructor Requirements
Consult the documentation in Extension
for details on
constructor requirements.
-
Method Summary
Modifier and Type Method Description Object
resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
Resolve an argument for theParameter
in the suppliedParameterContext
for the suppliedExtensionContext
.boolean
supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
Determine if this resolver supports resolution of an argument for theParameter
in the suppliedParameterContext
for the suppliedExtensionContext
.
-
Method Details
-
supportsParameter
boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionExceptionDetermine if this resolver supports resolution of an argument for theParameter
in the suppliedParameterContext
for the suppliedExtensionContext
.The
Method
orConstructor
in which the parameter is declared can be retrieved viaParameterContext.getDeclaringExecutable()
.- Parameters:
parameterContext
- the context for the parameter for which an argument should be resolved; nevernull
extensionContext
- the extension context for theExecutable
about to be invoked; nevernull
- Returns:
true
if this resolver can resolve an argument for the parameter- Throws:
ParameterResolutionException
- See Also:
resolveParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,ParameterContext
-
resolveParameter
Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionExceptionResolve an argument for theParameter
in the suppliedParameterContext
for the suppliedExtensionContext
.This method is only called by the framework if
supportsParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
previously returnedtrue
for the sameParameterContext
andExtensionContext
.The
Method
orConstructor
in which the parameter is declared can be retrieved viaParameterContext.getDeclaringExecutable()
.- Parameters:
parameterContext
- the context for the parameter for which an argument should be resolved; nevernull
extensionContext
- the extension context for theExecutable
about to be invoked; nevernull
- Returns:
- the resolved argument for the parameter; may only be
null
if the parameter type is not a primitive - Throws:
ParameterResolutionException
- See Also:
supportsParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,ParameterContext
-