@Test public void shouldCreateDefensiveCopyOfURLOnConstruction() throws Exception { URL mutableURL = getThreadContextClassLoader().getResource(EXISTING_RESOURCE); Asset asset = new UrlAsset(mutableURL); // mutate the URL - can't be sure that some malicious code or user won't do this? mutateURL(mutableURL); // now try to get a stream to read the asset InputStream io = null; try { io = asset.openStream(); } catch (Exception e) { Assert.fail("Mutated URL leaked into the UrlAsset"); } Assert.assertNotNull(io); Assert .assertEquals("Mutated URL leaked into the UrlAsset", "shrinkwrap=true", ApiTestUtils.convertToString(io)); }
@Test public void shouldBeAbleToReadURL() throws Exception { Asset asset = new UrlAsset(getThreadContextClassLoader().getResource(EXISTING_RESOURCE)); InputStream io = asset.openStream(); Assert.assertNotNull(io); Assert.assertEquals("Should be able to read the content of the resource", "shrinkwrap=true", ApiTestUtils.convertToString(io)); }
@Test public void shouldBeAbleToReturnURL() throws Exception { final URL url = getThreadContextClassLoader().getResource(EXISTING_RESOURCE); final Asset asset = new UrlAsset(url); Assert.assertTrue(url.sameFile(((UrlAsset)asset).getSource())); }