Compile Testing 是一个用来测试 Javac 和注释处理器的工具。
示例代码:
@RunWith(JUnit4.class) public class TreeContextTest { @Rule public final ExpectedException expectedExn = ExpectedException.none(); private static final String LITERAL_VALUE = "literal"; private static final ImmutableList<String> baseTreeSource = ImmutableList.of( "package test;", "", "final class TestClass {", " public String toString() {", " Object variable = new Object();", " return \"" + LITERAL_VALUE + "\" + variable;", " }", "", " public void nonsense() {", " int[] numbers = {0, 1, 2, 3, 4};", " for (int x : numbers) {", " if (x % 2 == 0) {", " throw new IllegalStateException();", " }", " }", " }", "}");