Revapi Java-based extensions test support

Contains utilities to ease testing extensions processing java code. Makes it easy to compile custom source files and subsequently analyze the compiled code using the java annotation processing APIs.

If you’re developing a Revapi extension you might find it useful to be able to compose a new jar file out of sources and resources present on the test classpath or somewhere on the filesystem and then be able to inspect the classes that you included in that jar.

Revapi offers a revapi-java-test-support artifact that may help you in JUnit4-based tests. It defines are rule that provides you with the means to compile jars and inspect the compiled classes using the Java annotation processing means.

The usage is simple. Just declare are rule in your test class:

@Rule
public Jar jar = new Jar();

and then use it in your test methods like so:

@Test
public void shouldTestSomething() {
    Jar.BuildOutput output = jar.from().classPathSources("/my-test/sources/", "com/acme/Acme.java").build();

    //access the built jar file
    File jarFile = output.jarFile();

    //inspect the compiled code
    Jar.Environment env = output.analyze();

    TypeElement type = env.elements().getTypeElement("com.acme.Acme");
    ...
}

Please consult the javadoc of the class for more information.

Back to top

Msb3 Maven skin by Marek Romanowski.