private static FileAndPath compileTestClass(long counter, String packageNameSuffix,
    String classNamePrefix) throws Exception {
    classNamePrefix = classNamePrefix + counter;
    String packageName = makePackageName(packageNameSuffix, counter);
    String javaPath = basePath + classNamePrefix + ".java";
    String classPath = basePath + classNamePrefix + ".class";
    PrintStream source = new PrintStream(javaPath);
    source.println("package " + packageName + ";");
    source.println(
      "public class " + classNamePrefix + " { public static void main(String[] args) { } };");
    source.close();
    JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
    int result = jc.run(null, null, null, javaPath);
    assertEquals(0, result);
    File classFile = new File(classPath);
    assertTrue(classFile.exists());
    return new FileAndPath(packageName.replace('.', '/') + '/', classFile);
  }
Compiles the test class with bogus code into a .class file. Unfortunately it's very tedious.
@param counter           Unique test counter.
@param packageNameSuffix Package name suffix (e.g. ".suffix") for nesting, or "".
@return The resulting .class file and the location in jar it is supposed to go to.
hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java