private void testClass(
      Class<? extends Supplier<ImmutableList<Object>>> c,
      ImmutableList<Object> constructorParameters)
      throws ReflectiveOperationException {
    TypeElement typeElement = compilationRule.getElements().getTypeElement(c.getCanonicalName());
    ExecutableElement constructorExecutable =
        Iterables.getOnlyElement(constructorsIn(typeElement.getEnclosedElements()));
    ImmutableList<TypeMirror> parameterTypeMirrors =
        constructorExecutable.getParameters().stream()
            .map(Element::asType)
            .map(compilationRule.getTypes()::erasure)
            .collect(toImmutableList());
    String className = "com.example.Forwarder";
    byte[] bytes =
        ForwardingClassGenerator.makeConstructorForwarder(
            className, typeElement.asType(), parameterTypeMirrors);
    // Now load the class we just generated, and use reflection to call its forwarding method.
    // That should give us an instance of the target class `c`, obtained by the call to its
    // constructor from the forwarding method.
    ClassLoader loader =
        new ClassLoader() {
          @Override
          protected Class<?> findClass(String name) throws ClassNotFoundException {
            if (name.equals(className)) {
              return defineClass(className, bytes, 0, bytes.length);
            }
            throw new ClassNotFoundException(name);
          }
        };
    Class<?> forwardingClass = Class.forName(className, true, loader);
    Method ofMethod = stream(forwardingClass.getDeclaredMethods()).findFirst().get();
    assertThat(ofMethod.getName()).isEqualTo("of");
    ofMethod.setAccessible(true);
    Supplier<ImmutableList<Object>> constructed =
        c.cast(ofMethod.invoke(null, constructorParameters.toArray()));
    ImmutableList<Object> retrievedParameters = constructed.get();
    assertThat(retrievedParameters).isEqualTo(constructorParameters);
  }
Tests that we can successfully generate a forwarding class that calls the constructor of the
given class. We'll then load the created class and call the forwarding method, checking that it
does indeed call the constructor.
value/src/test/java/com/google/auto/value/processor/ForwardingClassGeneratorTest.java