/**
   * Returns a class which has a static method with the same name as 'method', whose body creates an
   * new instance of 'specimen', casts it to 'iface' (including the type parameters) and invokes
   * 'method' upon it via an invokeinterface instruction with 'args' as function call parameters.
   */
  private Class invokeInterfaceHarness(
      Class specimen, Extends iface, AbstractMethod method, String... args) {
    Interface istub =
        new Interface(
            iface.getType().getName(),
            iface.getType().getAccessFlags(),
            iface.getType().getParameters(),
            null,
            Arrays.asList((Method) method));
    Class cstub = new Class(specimen.getName());

    String params = toJoinedString(args, ", ");

    ConcreteMethod sm =
        new ConcreteMethod(
            "int",
            SourceModel.stdMethodName,
            String.format(
                "return ((%s)(new %s())).%s(%s);",
                iface.toString(), specimen.getName(), method.getName(), params),
            new AccessFlag("public"),
            new AccessFlag("static"));
    sm.suppressWarnings();

    Class ii = new Class("II_" + specimen.getName() + "_" + iface.getType().getName(), sm);
    ii.addCompilationDependency(istub);
    ii.addCompilationDependency(cstub);
    ii.addCompilationDependency(method);
    return ii;
  }
  /**
   * Creates a class which calls target::method(args) via invokeinterface through 'iface', compiles
   * and loads both it and 'target', and then invokes the method. If the returned value does not
   * match 'value' then a test failure is indicated.
   */
  public void assertInvokeInterfaceEquals(
      Object value, Class target, Extends iface, AbstractMethod method, String... args) {

    Compiler compiler = compilerLocal.get();
    compiler.setFlags(compilerFlags());

    Class ii = invokeInterfaceHarness(target, iface, method, args);
    ClassLoader loader = compiler.compile(ii, target);

    assertStaticCallEquals(loader, ii, method.getName(), value);
    compiler.cleanup();
  }