Class CompilationExtension
java.lang.Object
be.imgn.gaia.processing.testing.CompilationExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstantiationAwareExtension
public final class CompilationExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.ParameterResolver
Gives tests the
Elements and Types of a running compilation, to test code that works on
javax.lang.model without writing an annotation processor around it.
@ExtendWith(CompilationExtension.class)
class MyTest {
@Test
void stringIsACharSequence(Elements elements, Types types) {
TypeMirror string = elements.getTypeElement("java.lang.String").asType();
TypeMirror charSequence = elements.getTypeElement("java.lang.CharSequence").asType();
assertThat(types.isAssignable(string, charSequence)).isTrue();
}
}
Each test that asks for them gets its own compilation, started by the first parameter that needs it and finished
when the test ends. A compilation asked for by a constructor or @BeforeAll parameter is shared by the tests
of the class, and so is the one of a class annotated with SharedCompilation. While the test runs, javac waits
inside an annotation processor, so the elements and types stay valid; they must not be kept beyond the test. The
compilation sees the JDK, and the class path and module path of the running JVM.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Constructor Summary
ConstructorsConstructorDescriptionCreates the extension; JUnit does, through@ExtendWith. -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
CompilationExtension
public CompilationExtension()Creates the extension; JUnit does, through@ExtendWith.
-
-
Method Details
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver
-