@Test
public void generateBuildFile() throws Exception {

  Map<String, String> definedClasses = new HashMap<>();
  LayoutlibClassLoader.generate(TestBuild.class, (name, classBytes) -> {
    StringWriter writer = new StringWriter();
    ClassReader reader = new ClassReader(classBytes);
    TraceClassVisitor visitor = new TraceClassVisitor(new PrintWriter(writer));
    reader.accept(visitor, 0);
    definedClasses.put(name, simplify(writer.toString()));
  });
  assertEquals(3, definedClasses.size()); // Outer class + 2 inner classes
  assertEquals("public class android/os/Build {\n" +
               "  public static INNERCLASS android/os/Build$InnerClass2 android/os/Build InnerClass2\n" +
               "  public static INNERCLASS android/os/Build$InnerClass android/os/Build InnerClass\n" +
               "  public final static Ljava/lang/String; TEST_FIELD = \"TestValue\"\n" +
               "  public <init>()V\n" +
               "  private static privateMethod()Ljava/lang/String;\n" +
               "  public static getSerial()Ljava/lang/String;\n" +
               "}",
               definedClasses.get("android.os.Build"));
  assertEquals("public class android/os/Build$InnerClass {\n" +
               "  public static INNERCLASS android/os/Build$InnerClass android/os/Build InnerClass\n" +
               "  public final static Ljava/lang/String; TEST_INNER_FIELD = \"TestInnerValue\"\n" +
               "  public final static I INNER_VALUE = 1\n" +
               "  public <init>()V\n" +
               "}",
               definedClasses.get("android.os.Build$InnerClass"));
  assertEquals("public class android/os/Build$InnerClass2 {\n" +
               "  public static INNERCLASS android/os/Build$InnerClass2 android/os/Build InnerClass2\n" +
               "  public final static Ljava/lang/String; TEST_INNER_FIELD2\n" +
               "  public <init>()V\n" +
               "  static <clinit>()V\n" +
               "}",
               definedClasses.get("android.os.Build$InnerClass2"));
}