Locator { public static ProgressCheck loadProgressCheck(final String impl) throws Exception { return loadProgressCheck(impl, null); } private  Locator(); static ProgressCheck loadProgressCheck(final String impl); static ProgressCheck loadProgressCheck(final String impl, final JsonObject config); static ProgressCheck loadProgressCheck(final String impl, final JsonObject config,
                                                  final ClassLoader classLoader); static ProgressCheck wrapWithAlias(final ProgressCheck progressCheck, final String alias); static List<ProgressCheck> loadFromCheckSpecs(final List<CheckSpec> checkSpecs); static List<ProgressCheck> loadFromCheckSpecs(final List<CheckSpec> checkSpecs,
                                                         final ClassLoader checkLoader);  }
@Test public void testLoadProgressCheck() throws Exception { assertNotNull("echo should load by class name", Locator.loadProgressCheck(Echo.class.getName())); assertNotNull("echo should load by class name, with config", Locator.loadProgressCheck(Echo.class.getName(), obj().get())); assertNotNull("echo should load by class name, with config, with cl", Locator.loadProgressCheck(Echo.class.getName(), obj().get(), getClass().getClassLoader())); assertNotNull("paths should load by factory class name, with config, with cl", Locator.loadProgressCheck(Paths.class.getName(), obj().get(), getClass().getClassLoader())); assertNotNull("simpleHandler.js should load by resource name, with config, with cl", Locator.loadProgressCheck("simpleHandler.js", obj().get(), getClass().getClassLoader())); assertNotNull("META-INF/../simpleHandler.js should load by resource name, with config, with cl", Locator.loadProgressCheck("META-INF/../simpleHandler.js", obj().get(), getClass().getClassLoader())); boolean notACheckThrew = false; try { Locator.loadProgressCheck(NotACheck.class.getName()); } catch (final Exception e) { notACheckThrew = true; } assertTrue("locator should throw when attempting to load NotACheck", notACheckThrew); boolean notAClassThrew = false; try { Locator.loadProgressCheck("com.example.NotARealClassName"); } catch (final Exception e) { notAClassThrew = true; assertTrue("locator should throw ClassNotFoundException when impl is not a real class name and not a script resource.", e instanceof ClassNotFoundException); } assertTrue("locator should throw when attempting to load NotARealClass", notAClassThrew); boolean notAScriptThrew = false; try { Locator.loadProgressCheck("scripts/notAScript.js"); } catch (final Exception e) { notAScriptThrew = true; } assertTrue("locator should throw when attempting to load a non-existent script", notAScriptThrew); }