Interface ClassTemplateInvocationContextProvider
-
- All Superinterfaces:
Extension
@API(status=MAINTAINED, since="5.13.3") public interface ClassTemplateInvocationContextProvider extends ExtensionClassTemplateInvocationContextProviderdefines the API forExtensionsthat wish to provide one or multiple contexts for the invocation of a@ClassTemplate.This extension point makes it possible to execute a class template in different contexts — for example, with different parameters, by preparing the test class instance differently, or multiple times without modifying the context.
This interface defines two main methods:
supportsClassTemplate(org.junit.jupiter.api.extension.ExtensionContext)andprovideClassTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext). The former is called by the framework to determine whether this extension wants to act on a container template that is about to be executed. If so, the latter is called and must return aStreamofClassTemplateInvocationContextinstances. Otherwise, this provider is ignored for the execution of the current class template.A provider that has returned
truefrom itssupportsClassTemplate(org.junit.jupiter.api.extension.ExtensionContext)method is called active. When multiple providers are active for a class template, theStreamsreturned by theirprovideClassTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext)methods will be chained, and the class template method will be invoked using the contexts of all active providers.An active provider may return zero invocation contexts from its
provideClassTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext)method if it overridesmayReturnZeroClassTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext)to returntrue.Constructor Requirements
Consult the documentation in
Extensionfor details on constructor requirements.- Since:
- 5.13
- See Also:
ClassTemplate,ClassTemplateInvocationContext
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleanmayReturnZeroClassTemplateInvocationContexts(ExtensionContext context)Signal that this provider may provide zero invocation contexts for the class template represented by the suppliedcontext.java.util.stream.Stream<? extends ClassTemplateInvocationContext>provideClassTemplateInvocationContexts(ExtensionContext context)Provide invocation contexts for the class template represented by the suppliedcontext.booleansupportsClassTemplate(ExtensionContext context)Determine if this provider supports providing invocation contexts for the class template represented by the suppliedcontext.
-
-
-
Method Detail
-
supportsClassTemplate
boolean supportsClassTemplate(ExtensionContext context)
Determine if this provider supports providing invocation contexts for the class template represented by the suppliedcontext.- Parameters:
context- the extension context for the class template about to be invoked; nevernull- Returns:
trueif this provider can provide invocation contexts- See Also:
provideClassTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext),ExtensionContext
-
provideClassTemplateInvocationContexts
java.util.stream.Stream<? extends ClassTemplateInvocationContext> provideClassTemplateInvocationContexts(ExtensionContext context)
Provide invocation contexts for the class template represented by the suppliedcontext.This method is only called by the framework if
supportsClassTemplate(org.junit.jupiter.api.extension.ExtensionContext)previously returnedtruefor the sameExtensionContext; this method is allowed to return an emptyStreambut notnull.The returned
Streamwill be properly closed by callingBaseStream.close(), making it safe to use a resource such asFiles.lines().- Parameters:
context- the extension context for the class template about to be invoked; nevernull- Returns:
- a
StreamofClassTemplateInvocationContextinstances for the invocation of the class template; nevernull - Throws:
TemplateInvocationValidationException- if a validation fails when while providing or closing theStream.- See Also:
supportsClassTemplate(org.junit.jupiter.api.extension.ExtensionContext),ExtensionContext
-
mayReturnZeroClassTemplateInvocationContexts
default boolean mayReturnZeroClassTemplateInvocationContexts(ExtensionContext context)
Signal that this provider may provide zero invocation contexts for the class template represented by the suppliedcontext.If this method returns
false(which is the default) and the provider returns an empty stream fromprovideClassTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext), this will be considered an execution error. Override this method to returntrueto ignore the absence of invocation contexts for this provider.- Parameters:
context- the extension context for the class template about to be invoked; nevernull- Returns:
trueto allow zero contexts,falseto fail execution in case of zero contexts
-
-