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

public Interface ParameterContext

extends AnnotatedElementContext
Annotations
@API
status:STABLE
since:5.0
Static Imports
org.apiguardian.api.API.Status.EXPERIMENTAL, .API.Status.STABLE

ParameterContext encapsulates the context in which an Executable will be invoked for a given Parameter.

A ParameterContext is used to support parameter resolution via a ParameterResolver.

Since
5.0
See Also
ParameterResolver, java.lang.reflect.Parameter, java.lang.reflect.Executable, java.lang.reflect.Method, java.lang.reflect.Constructor

Method Summary

Modifier and TypeMethod and Description
public default <A extends Annotation> Optional<A>
findAnnotation(Class<A>
the annotation type to search for; never null
annotationType
)

Overrides default org.junit.jupiter.api.extension.AnnotatedElementContext.findAnnotation.

Find the first annotation of annotationType that is either present or meta-present on the AnnotatedElement for this context.
public default <A extends Annotation> List<A>
findRepeatableAnnotations(Class<A>
the repeatable annotation type to search for; never null
annotationType
)

Overrides default org.junit.jupiter.api.extension.AnnotatedElementContext.findRepeatableAnnotations.

Find all repeatable annotations of annotationType that are either present or meta-present on the AnnotatedElement for this context.
public default AnnotatedElement
public default Executable

Returns:

the declaring Executable; never null
getDeclaringExecutable
()

Get the Executable (i.e., the java.lang.reflect.Method or java.lang.reflect.Constructor) that declares the Parameter for this context.

public int

Returns:

the index of the parameter
getIndex
()

Get the index of the Parameter for this context within the parameter list of the Executable that declares the parameter.

public Parameter

Returns:

the parameter; never null
getParameter
()

Get the Parameter for this context.

public Optional<Object>

Returns:

an Optional containing the target on which the Executable will be invoked; never null but will be empty if the Executable is a constructor or a static method.
getTarget
()

Get the target on which the Executable that declares the Parameter for this context will be invoked, if available.

public default boolean
isAnnotated(Class<? extends Annotation>
the annotation type to search for; never null
annotationType
)

Overrides default org.junit.jupiter.api.extension.AnnotatedElementContext.isAnnotated.

Determine if an annotation of annotationType is either present or meta-present on the AnnotatedElement for this context.

Method Detail

findAnnotationback to summary
public default <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType)

Overrides default org.junit.jupiter.api.extension.AnnotatedElementContext.findAnnotation.

Doc from org.junit.jupiter.api.extension.AnnotatedElementContext.findAnnotation.

Find the first annotation of annotationType that is either present or meta-present on the AnnotatedElement for this context.

WARNING

Favor the use of this method over directly invoking annotation lookup methods in the AnnotatedElement API due to a bug in javac on JDK versions prior to JDK 9.

Parameters
<A>
the annotation type
annotationType:Class<A>

the annotation type to search for; never null

Returns:Optional<A>

an Optional containing the annotation; never null but potentially empty

Annotations
@API
status:STABLE
since:5.10
@Override
Since
5.1.1
findRepeatableAnnotationsback to summary
public default <A extends Annotation> List<A> findRepeatableAnnotations(Class<A> annotationType)

Overrides default org.junit.jupiter.api.extension.AnnotatedElementContext.findRepeatableAnnotations.

Doc from org.junit.jupiter.api.extension.AnnotatedElementContext.findRepeatableAnnotations.

Find all repeatable annotations of annotationType that are either present or meta-present on the AnnotatedElement for this context.

WARNING

Favor the use of this method over directly invoking annotation lookup methods in the AnnotatedElement API due to a bug in javac on JDK versions prior to JDK 9.

Parameters
<A>
the annotation type
annotationType:Class<A>

the repeatable annotation type to search for; never null

Returns:List<A>

the list of all such annotations found; neither null nor mutable, but potentially empty

Annotations
@API
status:STABLE
since:5.10
@Override
Since
5.1.1
getAnnotatedElementback to summary
public default AnnotatedElement getAnnotatedElement()

Implements org.junit.jupiter.api.extension.AnnotatedElementContext.getAnnotatedElement.

Doc from org.junit.jupiter.api.extension.AnnotatedElementContext.getAnnotatedElement.

Get the AnnotatedElement for this context.

WARNING

When searching for annotations on the annotated element in this context, favor isAnnotated(Class), findAnnotation(Class), and findRepeatableAnnotations(Class) over methods in the AnnotatedElement API due to a bug in javac on JDK versions prior to JDK 9.

Returns:AnnotatedElement

the annotated element; never null

Annotations
@API
status:EXPERIMENTAL
since:5.10
@Override
Since
5.10
getDeclaringExecutableback to summary
public default Executable getDeclaringExecutable()

Get the Executable (i.e., the java.lang.reflect.Method or java.lang.reflect.Constructor) that declares the Parameter for this context.

Returns:Executable

the declaring Executable; never null

See Also
Parameter#getDeclaringExecutable()
getIndexback to summary
public int getIndex()

Get the index of the Parameter for this context within the parameter list of the Executable that declares the parameter.

Returns:int

the index of the parameter

See Also
getParameter(), Executable#getParameters()
getParameterback to summary
public Parameter getParameter()

Get the Parameter for this context.

WARNING

When searching for annotations on the parameter in this context, favor isAnnotated(Class), findAnnotation(Class), and findRepeatableAnnotations(Class) over methods in the Parameter API due to a bug in javac on JDK versions prior to JDK 9.

Returns:Parameter

the parameter; never null

See Also
getIndex()
getTargetback to summary
public Optional<Object> getTarget()

Get the target on which the Executable that declares the Parameter for this context will be invoked, if available.

Returns:Optional<Object>

an Optional containing the target on which the Executable will be invoked; never null but will be empty if the Executable is a constructor or a static method.

isAnnotatedback to summary
public default boolean isAnnotated(Class<? extends Annotation> annotationType)

Overrides default org.junit.jupiter.api.extension.AnnotatedElementContext.isAnnotated.

Doc from org.junit.jupiter.api.extension.AnnotatedElementContext.isAnnotated.

Determine if an annotation of annotationType is either present or meta-present on the AnnotatedElement for this context.

WARNING

Favor the use of this method over directly invoking AnnotatedElement#isAnnotationPresent(Class) due to a bug in javac on JDK versions prior to JDK 9.

Parameters
annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:boolean

true if the annotation is present or meta-present

Annotations
@API
status:STABLE
since:5.10
@Override
Since
5.1.1