FindClass extends Configured implements Tool { @Override public int run(String[] args) throws Exception { if (args.length != 2) { return usage(args); } String action = args[0]; String name = args[1]; int result; if (A_LOAD.equals(action)) { result = loadClass(name); } else if (A_CREATE.equals(action)) { result = loadClass(name); if (result == SUCCESS) { result = createClassInstance(name); } } else if (A_RESOURCE.equals(action)) { result = loadResource(name); } else if (A_PRINTRESOURCE.equals(action)) { result = dumpResource(name); } else { result = usage(args); } return result; } FindClass();  FindClass(Configuration conf); @VisibleForTesting static void setOutputStreams(PrintStream out, PrintStream err); @Override int run(String[] args); static void main(String[] args); static final String A_CREATE; static final String A_LOAD; static final String A_RESOURCE; static final String A_PRINTRESOURCE; static final int SUCCESS; }
@Test public void testFindsResource() throws Throwable { run(FindClass.SUCCESS, FindClass.A_RESOURCE, "org/apache/hadoop/util/TestFindClass.class"); }
@Test public void testFailsNoSuchResource() throws Throwable { run(FindClass.E_NOT_FOUND, FindClass.A_RESOURCE, "org/apache/hadoop/util/ThereIsNoSuchClass.class"); }
@Test public void testLoadFindsSelf() throws Throwable { run(FindClass.SUCCESS, FindClass.A_LOAD, "org.apache.hadoop.util.TestFindClass"); }
@Test public void testLoadFailsNoSuchClass() throws Throwable { run(FindClass.E_NOT_FOUND, FindClass.A_LOAD, "org.apache.hadoop.util.ThereIsNoSuchClass"); }
@Test public void testLoadWithErrorInStaticInit() throws Throwable { run(FindClass.E_LOAD_FAILED, FindClass.A_LOAD, "org.apache.hadoop.util.TestFindClass$FailInStaticInit"); }
@Test public void testCreateHandlesBadToString() throws Throwable { run(FindClass.SUCCESS, FindClass.A_CREATE, "org.apache.hadoop.util.TestFindClass$BadToStringClass"); }
@Test public void testCreatesClass() throws Throwable { run(FindClass.SUCCESS, FindClass.A_CREATE, "org.apache.hadoop.util.TestFindClass"); }
@Test public void testCreateFailsInStaticInit() throws Throwable { run(FindClass.E_LOAD_FAILED, FindClass.A_CREATE, "org.apache.hadoop.util.TestFindClass$FailInStaticInit"); }
@Test public void testCreateFailsInConstructor() throws Throwable { run(FindClass.E_CREATE_FAILED, FindClass.A_CREATE, "org.apache.hadoop.util.TestFindClass$FailInConstructor"); }
@Test public void testCreateFailsNoEmptyConstructor() throws Throwable { run(FindClass.E_CREATE_FAILED, FindClass.A_CREATE, "org.apache.hadoop.util.TestFindClass$NoEmptyConstructor"); }
@Test public void testLoadPrivateClass() throws Throwable { run(FindClass.SUCCESS, FindClass.A_LOAD, "org.apache.hadoop.util.TestFindClass$PrivateClass"); }
@Test public void testCreateFailsPrivateClass() throws Throwable { run(FindClass.E_CREATE_FAILED, FindClass.A_CREATE, "org.apache.hadoop.util.TestFindClass$PrivateClass"); }
@Test public void testCreateFailsInPrivateConstructor() throws Throwable { run(FindClass.E_CREATE_FAILED, FindClass.A_CREATE, "org.apache.hadoop.util.TestFindClass$PrivateConstructor"); }
@Test public void testLoadFindsLog4J() throws Throwable { run(FindClass.SUCCESS, FindClass.A_RESOURCE, LOG4J_PROPERTIES); }