### Question:
DefaultJsUriManager implements JsUriManager { public JsUri processExternJsUri(Uri uri) throws GadgetException { String container = uri.getQueryParameter(Param.CONTAINER.getKey()); if (container == null) { container = ContainerConfig.DEFAULT_CONTAINER; } getReqConfig(container, JS_HOST_PARAM); String jsPrefix = getReqConfig(container, JS_PATH_PARAM); String host = uri.getAuthority(); if (host == null) { issueUriFormatError("Unexpected: Js Uri has no host"); return INVALID_URI; } String path = uri.getPath(); if (path == null) { issueUriFormatError("Unexpected: Js Uri has no path"); return INVALID_URI; } if (!path.startsWith(jsPrefix)) { issueUriFormatError("Js Uri path invalid, expected prefix: " + jsPrefix + ", is: " + path); return INVALID_URI; } path = path.substring(jsPrefix.length()); if (path.endsWith(JS_SUFFIX)) { path = path.substring(0, path.length() - JS_SUFFIX.length()); } while (path.startsWith("/")) { path = path.substring(1); } Collection<String> libs = getJsLibs(path); UriStatus status = UriStatus.VALID_UNVERSIONED; String version = uri.getQueryParameter(Param.VERSION.getKey()); if (version != null && versioner != null) { Uri gadgetUri = null; String gadgetParam = uri.getQueryParameter(Param.URL.getKey()); if (gadgetParam != null) { gadgetUri = Uri.parse(gadgetParam); } status = versioner.validate(gadgetUri, container, libs, version); } return new JsUri(status, libs); } @Inject  DefaultJsUriManager(ContainerConfig config,
                             Versioner versioner); Uri makeExternJsUri(Gadget gadget, Collection<String> extern); JsUri processExternJsUri(Uri uri);  }### Answer:
@Test(expected = RuntimeException.class) public void processMissingHostConfig() throws GadgetException { ContainerConfig config = mockConfig(null, "/gadgets/js"); DefaultJsUriManager manager = makeManager(config, null); manager.processExternJsUri(Uri.parse("http: }
@Test(expected = RuntimeException.class) public void processMissingPathConfig() throws GadgetException { ContainerConfig config = mockConfig("foo", null); DefaultJsUriManager manager = makeManager(config, null); manager.processExternJsUri(Uri.parse("http: }
@Test public void processDefaultConfig() throws GadgetException { ContainerConfig config = mockDefaultConfig("foo", "/gadgets/js"); DefaultJsUriManager manager = makeManager(config, null); manager.processExternJsUri(Uri.parse("http: }
@Test public void processPathPrefixMismatch() throws GadgetException { String targetHost = "target-host.org"; ContainerConfig config = mockConfig("http: TestDefaultJsUriManager manager = makeManager(config, null); Uri testUri = Uri.parse("http: Param.CONTAINER.getKey() + '=' + CONTAINER); JsUri jsUri = manager.processExternJsUri(testUri); assertTrue(manager.hadError()); assertEquals(jsUri.getStatus(), UriStatus.BAD_URI); assertSame(DefaultJsUriManager.INVALID_URI, jsUri); }
@Test public void processPathSuffixNoJs() throws GadgetException { String targetHost = "target-host.org"; ContainerConfig config = mockConfig("http: TestDefaultJsUriManager manager = makeManager(config, null); Uri testUri = Uri.parse("http: Param.CONTAINER.getKey() + '=' + CONTAINER); JsUri jsUri = manager.processExternJsUri(testUri); assertFalse(manager.hadError()); assertEquals(jsUri.getStatus(), UriStatus.VALID_UNVERSIONED); List<String> extern = Lists.newArrayList("feature", "another"); assertCollectionEquals(jsUri.getLibs(), extern); }