/** * Tests <code>ResourceLoader#getPackageResourceAsFile</code> methods. * * @throws IOException should not happen */ @Test public void testPackageResourceAsFile() throws IOException { assertReadable(ResourceLoader.getPackageResourceAsFile(getThisPackage(), getExistingResourceName())); assert ResourceLoader.getPackageResourceAsFile(getThisPackage(), getNonExistingResourceName()) == null; assertReadable(ResourceLoader.getPackageResourceAsFile(getThisPackage(), getExistingResourceName(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getPackageResourceAsFile(getThisPackage(), getNonExistingResourceName(), getThisClassLoader(), getRootPackageFile()) == null; }
/** * Tests <code>ResourceLoader#getResourceAsFile</code> methods. * * @throws IOException should not happen */ @Test public void testResourceAsFile() throws IOException { assertReadable(ResourceLoader.getResourceAsFile(getExistingResourcePath())); assertReadable(ResourceLoader.getResourceAsFile("/"+getExistingResourcePath())); assert ResourceLoader.getResourceAsFile(getNonExistingResourcePath()) == null; assertReadable(ResourceLoader.getResourceAsFile(getExistingResourcePath(), getThisClassLoader(), getRootPackageFile())); assertReadable(ResourceLoader.getResourceAsFile("/"+getExistingResourcePath(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getResourceAsFile(getNonExistingResourcePath(), getThisClassLoader(), getRootPackageFile()) == null; }
private void assertReadable(AbstractFile file) throws IOException { assert file != null; assertReadable(file.getInputStream()); assert file.exists(); }
private String getNonExistingResourcePath() { return "com/mucommander/commons/file/util/"+getNonExistingResourceName(); } }
private String getExistingResourcePath() { return "com/mucommander/commons/file/util/"+getExistingResourceName(); }
/** * Tests {@link ResourceLoader#getRelativePackagePath(Package)}. */ @Test public void testRelativePackagePath() { // Returned path does not end with a '/' assert "com/mucommander/commons/file/util".equals(ResourceLoader.getRelativePackagePath(getThisPackage())); }
/** * Tests <code>ResourceLoader#getRootPackageAsFile</code> methods. * * @throws IOException should not happen */ @Test public void testRootPackageAsFile() throws IOException { AbstractFile rootPackageFile = ResourceLoader.getRootPackageAsFile(getClass()); assert rootPackageFile != null; assert rootPackageFile.exists(); assert rootPackageFile.isBrowsable(); AbstractFile thisClassFile = rootPackageFile.getChild("com/mucommander/commons/file/util/ResourceLoaderTest.class"); assertReadable(thisClassFile); }
/** * Tests <code>ResourceLoader#getPackageResourceAsURL</code> methods. * * @throws IOException should not happen */ @Test public void testPackageResourceAsURL() throws IOException { assertReadable(ResourceLoader.getPackageResourceAsURL(getThisPackage(), getExistingResourceName())); assert ResourceLoader.getPackageResourceAsURL(getThisPackage(), getNonExistingResourceName()) == null; assertReadable(ResourceLoader.getPackageResourceAsURL(getThisPackage(), getExistingResourceName(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getPackageResourceAsURL(getThisPackage(), getNonExistingResourceName(), getThisClassLoader(), getRootPackageFile()) == null; }
/** * Tests <code>ResourceLoader#getResourceAsURL</code> methods. * * @throws IOException should not happen */ @Test public void testResourceAsURL() throws IOException { assertReadable(ResourceLoader.getResourceAsURL(getExistingResourcePath())); assertReadable(ResourceLoader.getResourceAsURL("/"+getExistingResourcePath())); assert ResourceLoader.getResourceAsURL(getNonExistingResourcePath()) == null; assertReadable(ResourceLoader.getResourceAsURL(getExistingResourcePath(), getThisClassLoader(), getRootPackageFile())); assertReadable(ResourceLoader.getResourceAsURL("/"+getExistingResourcePath(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getResourceAsURL(getNonExistingResourcePath(), getThisClassLoader(), getRootPackageFile()) == null; }
/** * Tests <code>ResourceLoader#getPackageResourceAsStream</code> methods. * * @throws IOException should not happen */ @Test public void testPackageResourceAsStream() throws IOException { assertReadable(ResourceLoader.getPackageResourceAsStream(getThisPackage(), getExistingResourceName())); assert ResourceLoader.getPackageResourceAsStream(getThisPackage(), getNonExistingResourceName()) == null; assertReadable(ResourceLoader.getPackageResourceAsStream(getThisPackage(), getExistingResourceName(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getPackageResourceAsStream(getThisPackage(), getNonExistingResourceName(), getThisClassLoader(), getRootPackageFile()) == null; }
/** * Tests <code>ResourceLoader#getResourceAsStream</code> methods. * * @throws IOException should not happen */ @Test public void testResourceAsStream() throws IOException { assertReadable(ResourceLoader.getResourceAsStream(getExistingResourcePath())); assertReadable(ResourceLoader.getResourceAsStream("/"+getExistingResourcePath())); assert ResourceLoader.getResourceAsStream(getNonExistingResourcePath()) == null; assertReadable(ResourceLoader.getResourceAsStream(getExistingResourcePath(), getThisClassLoader(), getRootPackageFile())); assertReadable(ResourceLoader.getResourceAsStream("/"+getExistingResourcePath(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getResourceAsStream(getNonExistingResourcePath(), getThisClassLoader(), getRootPackageFile()) == null; }