I\'m experimenting with java annotation processors. I\'m able to write integration tests using the \"JavaCompiler\" (in fact I\'m using \"hickory\" at the moment). I can run the
jOOR is a small Java reflection library that also provides simplified access to the in-memory Java compilation API in javax.tool.JavaCompiler
. We added support for this to unit test jOOQ's annotation processors. You can easily write unit tests like this:
@Test
public void testCompileWithAnnotationProcessors() {
AProcessor p = new AProcessor();
try {
Reflect.compile(
"org.joor.test.FailAnnotationProcessing",
"package org.joor.test; " +
"@A " +
"public class FailAnnotationProcessing { " +
"}",
new CompileOptions().processors(p)
).create().get();
Assert.fail();
}
catch (ReflectException expected) {
assertFalse(p.processed);
}
}
The above example has been taken from this blog post