Interface ParameterResolver
-
- All Superinterfaces:
Extension,TestInstantiationAwareExtension
- All Known Implementing Classes:
TypeBasedParameterResolver
@API(status=STABLE, since="5.0") public interface ParameterResolver extends TestInstantiationAwareExtensionParameterResolverdefines the API forExtensionsthat wish to dynamically resolve arguments for parameters at runtime.If a constructor for a test class or a
@Test,@BeforeEach,@AfterEach,@BeforeAll, or@AfterAllmethod declares a parameter, an argument for the parameter must be resolved at runtime by aParameterResolver.By default, when the methods in this interface are called for a test class constructor, the supplied
ExtensionContextrepresents the test class that's about to be instantiated. Extensions may overrideTestInstantiationAwareExtension.getTestInstantiationExtensionContextScope(org.junit.jupiter.api.extension.ExtensionContext)to returnTEST_METHODin order to change the scope of theExtensionContextto the test method, unless thePER_CLASSlifecycle is used. Changing the scope makes test-specific data available to the implementation of this method and allows keeping state on the test level by using the providedStoreinstance.Constructor Requirements
Consult the documentation in
Extensionfor details on constructor requirements.ExtensionContextScopeAs of JUnit Jupiter 5.12, this API participates in the
TestInstantiationAwareExtensioncontract. Implementations of this API may therefore choose to overridegetTestInstantiationExtensionContextScope(ExtensionContext)to require a test-method scopedExtensionContext.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
TestInstantiationAwareExtension.ExtensionContextScope
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.ObjectresolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)Resolve an argument for theParameterin the suppliedParameterContextfor the suppliedExtensionContext.booleansupportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)Determine if this resolver supports resolution of an argument for theParameterin the suppliedParameterContextfor the suppliedExtensionContext.-
Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
-
-
-
Method Detail
-
supportsParameter
boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException
Determine if this resolver supports resolution of an argument for theParameterin the suppliedParameterContextfor the suppliedExtensionContext.The
MethodorConstructorin which the parameter is declared can be retrieved viaParameterContext.getDeclaringExecutable().- Parameters:
parameterContext- the context for the parameter for which an argument should be resolved; nevernullextensionContext- the extension context for theExecutableabout to be invoked; nevernull- Returns:
trueif 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
java.lang.Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException
Resolve an argument for theParameterin the suppliedParameterContextfor 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 returnedtruefor the sameParameterContextandExtensionContext.The
MethodorConstructorin which the parameter is declared can be retrieved viaParameterContext.getDeclaringExecutable().- Parameters:
parameterContext- the context for the parameter for which an argument should be resolved; nevernullextensionContext- the extension context for theExecutableabout to be invoked; nevernull- Returns:
- the resolved argument for the parameter; may only be
nullif 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
-
-