Top Description Inners Constructors Methods
org.junit.jupiter.engine.extension

pack-priv Class TestInfoParameterResolver

extends Object
implements ParameterResolver
Class Inheritance
All Implemented Interfaces
org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstantiationAwareExtension, org.junit.jupiter.api.extension.Extension
Imports
java.lang.reflect.Method, java.util.Optional, .Set, org.jspecify.annotations.Nullable, org.junit.jupiter.api.TestInfo, org.junit.jupiter.api.extension.ExtensionContext, .ParameterContext, .ParameterResolver, org.junit.platform.commons.util.ToStringBuilder

ParameterResolver that resolves the TestInfo for the currently executing test.
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public TestInstantiationAwareExtension.ExtensionContextScope
getTestInstantiationExtensionContextScope(ExtensionContext rootContext)

Overrides default org.junit.jupiter.api.extension.TestInstantiationAwareExtension.getTestInstantiationExtensionContextScope.

Determine whether this extension should receive a test-method scoped ExtensionContext during the instantiation of test classes or processing of test instances.

public TestInfo
resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.resolveParameter.

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

public boolean
supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.supportsParameter.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TestInfoParameterResolverback to summary
pack-priv TestInfoParameterResolver()

Method Detail

getTestInstantiationExtensionContextScopeback to summary
public TestInstantiationAwareExtension.ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext)

Overrides default org.junit.jupiter.api.extension.TestInstantiationAwareExtension.getTestInstantiationExtensionContextScope.

Doc from org.junit.jupiter.api.extension.TestInstantiationAwareExtension.getTestInstantiationExtensionContextScope.

Determine whether this extension should receive a test-method scoped ExtensionContext during the instantiation of test classes or processing of test instances.

If an extension returns TEST_METHOD from this method, methods defined in the following extension APIs will be called with a test-method scoped ExtensionContext instead of a test-class scoped context. Note, however, that a test-class scoped context will always be supplied if the PER_CLASS test instance lifecycle is used.

When a test-method scoped ExtensionContext is supplied, implementations of the above extension APIs will observe the following differences.

Note

The behavior which is enabled by returning TEST_METHOD from this method will become the default in future versions of JUnit. To ensure forward compatibility, extension authors are therefore advised to opt into this feature, even if they do not require the new functionality.

Annotations
@Override
resolveParameterback to summary
public TestInfo resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.resolveParameter.

Doc from org.junit.jupiter.api.extension.ParameterResolver.resolveParameter.

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().

Annotations
@Override
supportsParameterback to summary
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.supportsParameter.

Doc from org.junit.jupiter.api.extension.ParameterResolver.supportsParameter.

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().

Annotations
@Override
org.junit.jupiter.engine.extension back to summary

private Class TestInfoParameterResolver.DefaultTestInfo

extends Object
implements TestInfo
Class Inheritance
  • java.lang.Object
  • org.junit.jupiter.engine.extension.TestInfoParameterResolver.DefaultTestInfo
All Implemented Interfaces
org.junit.jupiter.api.TestInfo

Field Summary

Modifier and TypeField and Description
private final String
private final Set<String>
private final Optional<Class<?>>
private final Optional<Method>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
getDisplayName()

Implements org.junit.jupiter.api.TestInfo.getDisplayName.

Get the display name of the current test or container.

public Set<String>
getTags()

Implements org.junit.jupiter.api.TestInfo.getTags.

Get the set of all tags for the current test or container.

public Optional<Class<?>>
getTestClass()

Implements org.junit.jupiter.api.TestInfo.getTestClass.

Get the Class associated with the current test or container, if available.

public Optional<Method>
getTestMethod()

Implements org.junit.jupiter.api.TestInfo.getTestMethod.

Get the Method associated with the current test or container, if available.

private static @Nullable Object
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

displayNameback to summary
private final String displayName
tagsback to summary
private final Set<String> tags
testClassback to summary
private final Optional<Class<?>> testClass
testMethodback to summary
private final Optional<Method> testMethod

Constructor Detail

DefaultTestInfoback to summary
pack-priv DefaultTestInfo(ExtensionContext extensionContext)

Method Detail

getDisplayNameback to summary
public String getDisplayName()

Implements org.junit.jupiter.api.TestInfo.getDisplayName.

Doc from org.junit.jupiter.api.TestInfo.getDisplayName.

Get the display name of the current test or container.

The display name is either a default name or a custom name configured via @DisplayName.

Default Display Names

If the context in which TestInfo is used is at the container level, the default display name is generated based on the name of the test class. For top-level and @Nested test classes, the default display name is the simple name of the class. For static nested test classes, the default display name is the default display name for the enclosing class concatenated with the simple name of the static nested class, separated by a dollar sign ($). For example, the default display names for the following test classes are TopLevelTests, NestedTests, and TopLevelTests$StaticTests.

  class TopLevelTests {

     @Nested
     class NestedTests {}

     static class StaticTests {}
  }

If the context in which TestInfo is used is at the test level, the default display name is the name of the test method concatenated with a comma-separated list of simple names of the parameter types in parentheses. For example, the default display name for the following test method is testUser(TestInfo, User).

  @Test
  void testUser(TestInfo testInfo, @Mock User user) {}

Note that display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.

Annotations
@Override
getTagsback to summary
public Set<String> getTags()

Implements org.junit.jupiter.api.TestInfo.getTags.

Doc from org.junit.jupiter.api.TestInfo.getTags.

Get the set of all tags for the current test or container.

Tags may be declared directly on the test element or inherited from an outer context.

Annotations
@Override
getTestClassback to summary
public Optional<Class<?>> getTestClass()

Implements org.junit.jupiter.api.TestInfo.getTestClass.

Doc from org.junit.jupiter.api.TestInfo.getTestClass.

Get the Class associated with the current test or container, if available.

Annotations
@Override
getTestMethodback to summary
public Optional<Method> getTestMethod()

Implements org.junit.jupiter.api.TestInfo.getTestMethod.

Doc from org.junit.jupiter.api.TestInfo.getTestMethod.

Get the Method associated with the current test or container, if available.

Annotations
@Override
nullSafeGetback to summary
private static @Nullable Object nullSafeGet(@Nullable Optional<?> optional)
Annotations
@SuppressWarnings:OptionalAssignedToNull, NullableOptional
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override