TestRule for creating javax.lang.model instances in a unit
test.
The standard javax.lang.model.util objects, and TypeMirror instances for existing classes, are readily available. More complex elements can be constructed from Java source code snippets,
allowing top-level types and even code with errors in to be contained within a single test
method.
@RunWith(JUnit4.class)
public class TypeUtilsTest {
@Rule public final ModelRule model = new ModelRule();
@Test
public void aTest() {
TypeMirror intType = model.typeMirror(int.class);
TypeElement myType = model.newType(
"package my.test.package;",
"public class MyType {",
" public void aMethod(int anArg);",
"}");
...