RDescriptionUtils { public static Map<String, String> extractDescriptionFromArchive(final String filename, InputStream is) { checkNotNull(filename); checkNotNull(is); final String lowerCaseFilename = filename.toLowerCase(); if (lowerCaseFilename.endsWith(".tar.gz") || lowerCaseFilename.endsWith(".tgz")) { return extractMetadataFromTgz(is); } else if (lowerCaseFilename.endsWith(".gz")) { return extractMetadataFromGz(is); } else if (lowerCaseFilename.endsWith(".zip")) { return extractMetadataFromZip(is); } throw new IllegalStateException("Unexpected file extension for file: " + filename); } private  RDescriptionUtils(); static Map<String, String> extractDescriptionFromArchive(final String filename, InputStream is);  }
@Test(expected = IllegalStateException.class) public void illegalStateExceptionWhenUnsupportedType() throws Exception { extractDescriptionFromArchive("Unsupported.unsuppored", inputStream); }
@Test(expected = NullPointerException.class) public void nullPointerWhenNullFilename() throws Exception { extractDescriptionFromArchive(null, inputStream); }
@Test(expected = NullPointerException.class) public void nullPointerWhenNullInputStream() throws Exception { extractDescriptionFromArchive("file", null); }
@Test public void extractDescriptionFromTar() throws Exception { Map<String, String> attributes = extractDescriptionFromArchive("r-package.tar.gz", loadFile("r-package.tar.gz")); assertAttributes(attributes); }
@Test public void extractDescriptionFromTgz() throws Exception { Map<String, String> attributes = extractDescriptionFromArchive("r-package.tgz", loadFile("r-package.tar.gz")); assertAttributes(attributes); }
@Test public void extractDescriptionFromZip() throws Exception { Map<String, String> attributes = extractDescriptionFromArchive("r-package.zip", loadFile("r-package.zip")); assertAttributes(attributes); }
@Test(expected = RException.class) public void rExceptionOnCompressorException() throws Exception { extractDescriptionFromArchive("r-package.tar.gz", inputStream); }
@Test(expected = IllegalStateException.class) public void illegalStateExceptionWhenNoMetadata() throws Exception { extractDescriptionFromArchive("r-package-no-description.zip", loadFile("r-package-no-description.zip")); }