Top Description Methods
org.junit.jupiter.api.extension

public Interface ParameterResolver

extends Extension
Known Direct Implementers
org.junit.jupiter.api.extension.support.TypeBasedParameterResolver
Annotations
@API
status:STABLE
since:5.0
Static Imports
org.apiguardian.api.API.Status.STABLE

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.

Since
5.0
See Also
supportsParameter(ParameterContext, ExtensionContext), resolveParameter(ParameterContext, ExtensionContext), ParameterContext, TestInstanceFactory, TestInstancePostProcessor, TestInstancePreDestroyCallback

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the resolved argument for the parameter; may only be null if the parameter type is not a primitive
resolveParameter
(ParameterContext
the context for the parameter for which an argument should be resolved; never null
parameterContext
,
ExtensionContext
the extension context for the Executable about to be invoked; never null
extensionContext
)

Resolve an argument for the Parameter in the supplied ParameterContext for the supplied ExtensionContext.

public boolean

Returns:

true if this resolver can resolve an argument for the parameter
supportsParameter
(ParameterContext
the context for the parameter for which an argument should be resolved; never null
parameterContext
,
ExtensionContext
the extension context for the Executable about to be invoked; never null
extensionContext
)

Determine if this resolver supports resolution of an argument for the Parameter in the supplied ParameterContext for the supplied ExtensionContext.

Method Detail

resolveParameterback to summary
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException

Resolve an argument for the Parameter in the supplied ParameterContext for the supplied ExtensionContext.

This method is only called by the framework if supportsParameter previously returned true for the same ParameterContext and ExtensionContext.

The java.lang.reflect.Method or java.lang.reflect.Constructor in which the parameter is declared can be retrieved via ParameterContext#getDeclaringExecutable().

Parameters
parameterContext:ParameterContext

the context for the parameter for which an argument should be resolved; never null

extensionContext:ExtensionContext

the extension context for the Executable about to be invoked; never null

Returns:Object

the resolved argument for the parameter; may only be null if the parameter type is not a primitive

See Also
supportsParameter, ParameterContext
supportsParameterback to summary
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException

Determine if this resolver supports resolution of an argument for the Parameter in the supplied ParameterContext for the supplied ExtensionContext.

The java.lang.reflect.Method or java.lang.reflect.Constructor in which the parameter is declared can be retrieved via ParameterContext#getDeclaringExecutable().

Parameters
parameterContext:ParameterContext

the context for the parameter for which an argument should be resolved; never null

extensionContext:ExtensionContext

the extension context for the Executable about to be invoked; never null

Returns:boolean

true if this resolver can resolve an argument for the parameter

See Also
resolveParameter, ParameterContext