Package com.karuslabs.elementary.junit
Class ToolsExtension
java.lang.Object
com.karuslabs.elementary.junit.ToolsExtension
- All Implemented Interfaces:
Consumer<LabelSource>,AfterAllCallback,Extension,InvocationInterceptor,ParameterResolver,TestInstanceFactory,ArgumentsProvider,AnnotationConsumer<LabelSource>
public class ToolsExtension
extends Object
implements ArgumentsProvider, AnnotationConsumer<LabelSource>, ParameterResolver
A JUnit extension that provides an annotation processing environment in which
to execute tests. The annotation processing utilities can be accessed either
via
Java source files may be included for compilation by annotating the test class with
Elements can be used in parameterized tests using
Tools or injected through the test class's constructor or test method's
parameters.
Java source files may be included for compilation by annotating the test class with
@Classpath, @Inline, @Introspect or @Resource.
Elements can be used in parameterized tests using
@LabelSource.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
InvocationInterceptor.Invocation<T extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(LabelSource source) voidafterAll(ExtensionContext context) Tears down the compiler.createTestInstance(TestInstanceFactoryContext factory, ExtensionContext context) Starts the compiler and creates an instance of the test class if it has only 1 constructor with supported parameters.voidinterceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> method, ExtensionContext context) Intercepts a test method invocation to determine if it is annotated withClasspath,@Resourceor@Inline.provideArguments(ExtensionContext context) resolveParameter(ParameterContext parameter, ExtensionContext context) booleansupportsParameter(ParameterContext parameter, ExtensionContext context) Tests if a parameter is supported.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
interceptAfterAllMethod, interceptAfterEachMethod, interceptBeforeAllMethod, interceptBeforeEachMethod, interceptDynamicTest, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestTemplateMethod
-
Constructor Details
-
ToolsExtension
public ToolsExtension()
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<LabelSource>
-
provideArguments
- Specified by:
provideArgumentsin interfaceArgumentsProvider- Throws:
Exception
-
resolveParameter
public Object resolveParameter(ParameterContext parameter, ExtensionContext context) throws ParameterResolutionException - Specified by:
resolveParameterin interfaceParameterResolver- Throws:
ParameterResolutionException
-
supportsParameter
Tests if a parameter is supported. All types returned by the methods inToolsare supported.- Specified by:
supportsParameterin interfaceParameterResolver- Parameters:
parameter- the parmaeter's contextcontext- this extension's context- Returns:
trueif the parameter is supported; otherwisefalse
-
createTestInstance
public Object createTestInstance(TestInstanceFactoryContext factory, ExtensionContext context) throws TestInstantiationException Starts the compiler and creates an instance of the test class if it has only 1 constructor with supported parameters.- Specified by:
createTestInstancein interfaceTestInstanceFactory- Parameters:
factory- the factorycontext- the extension context- Returns:
- an instance of the test class
- Throws:
TestInstantiationException- if the test class has more than 1 constructorUnsupportedOperationException- if parallel test execution is enabled
-
interceptTestMethod
public void interceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> method, ExtensionContext context) throws Throwable Intercepts a test method invocation to determine if it is annotated withClasspath,@Resourceor@Inline.- Specified by:
interceptTestMethodin interfaceInvocationInterceptor- Parameters:
invocation- the invocationmethod- the methodcontext- the context- Throws:
IllegalArgumentException- if the test method is annotated with@Resourceor@InlineThrowable- if the invocation throws an exception
-
afterAll
Tears down the compiler.- Specified by:
afterAllin interfaceAfterAllCallback- Parameters:
context- the context
-