SignatureManagerImpl implements SignatureManager { @Override public Map<SignatureType, SortedMap<String, SignatureFileInfo>> getAvailableSignatureFiles() { final Path binSigFileDir = config.getSignatureFileDir(); final Path containerSigFileDir = config.getContainerSignatureDir(); final DirectoryStream.Filter<Path> xmlExtensionFilter = new DirectoryStream.Filter<Path>() { @Override public boolean accept(final Path path) { return (!Files.isDirectory(path)) && FileUtil.fileName(path).endsWith(".xml"); } }; final Map<SignatureType, SortedMap<String, SignatureFileInfo>> availableSigFiles = new HashMap<>(); SignatureInfoParser parser = new SignatureInfoParser(); final String errorMessagePattern = "Unreadable signature file [%s]"; final SortedMap<String, SignatureFileInfo> binSigFiles = new TreeMap<>(); for (final Path file : FileUtil.listFilesQuietly(binSigFileDir, false, xmlExtensionFilter)) { String fileName = FilenameUtils.getBaseName(FileUtil.fileName(file)); try { binSigFiles.put(fileName, forBinarySigFile(file, parser)); } catch (SignatureFileException e) { log.warn(String.format(errorMessagePattern, file)); } } final SortedMap<String, SignatureFileInfo> containerSigFiles = new TreeMap<>(); for (final Path file : FileUtil.listFilesQuietly(containerSigFileDir, false, xmlExtensionFilter)) { String fileName = FilenameUtils.getBaseName(FileUtil.fileName(file)); try { containerSigFiles.put(fileName, forSimpleVersionedFile(file, SignatureType.CONTAINER)); } catch (SignatureFileException e) { log.warn(String.format(errorMessagePattern, file)); } } availableSigFiles.put(SignatureType.BINARY, binSigFiles); availableSigFiles.put(SignatureType.CONTAINER, containerSigFiles); return availableSigFiles; } SignatureManagerImpl();  SignatureManagerImpl(DroidGlobalConfig config, Map<SignatureType, SignatureUpdateService> updateServices); void init(); @Override Map<SignatureType, SortedMap<String, SignatureFileInfo>> getAvailableSignatureFiles(); void setConfig(DroidGlobalConfig config); @Override Map<SignatureType, SignatureFileInfo> getLatestSignatureFiles(); void setSignatureUpdateServices(Map<SignatureType, SignatureUpdateService> signatureUpdateServices); @Override SignatureFileInfo downloadLatest(final SignatureType type); @Override Map<SignatureType, SignatureFileInfo> getDefaultSignatures(); @Override SignatureFileInfo install(final SignatureType type, final Path signatureFile, final boolean setDefault);  }
@Test public void testGetAvailableSignatureFiles() { Map<SignatureType, SortedMap<String, SignatureFileInfo>> infos = signatureManager.getAvailableSignatureFiles(); Map<String, SignatureFileInfo> binaryInfos = infos.get(SignatureType.BINARY); assertEquals(16, binaryInfos.get("DROID_SignatureFile_V16").getVersion()); assertEquals(26, binaryInfos.get("DROID_SignatureFile_V26").getVersion()); assertEquals(16, binaryInfos.get("malformed").getVersion()); assertEquals(2, infos.size()); }
@Test public void testGetAvailableContainerSignatureFiles() throws IOException { deleteSigDirs(); createSigDirs(); final Path containerSigFile1 = containerSigFileDir.resolve("container_sigs-20100927.xml"); final Path containerSigFile2 = containerSigFileDir.resolve("container_sigs-20100827.xml"); Files.createFile(containerSigFile1); Files.createFile(containerSigFile2); assertTrue(Files.exists(containerSigFile1)); assertTrue(Files.exists(containerSigFile2)); Map<SignatureType, SortedMap<String, SignatureFileInfo>> sigFiles = signatureManager.getAvailableSignatureFiles(); SortedMap<String, SignatureFileInfo> containerSigFiles = sigFiles.get(SignatureType.CONTAINER); assertEquals(2, containerSigFiles.size()); assertEquals(containerSigFile1, containerSigFiles.get("container_sigs-20100927").getFile()); assertEquals(containerSigFile2, containerSigFiles.get("container_sigs-20100827").getFile()); assertEquals(containerSigFileDir.resolve("container_sigs-20100927.xml"), containerSigFiles.get("container_sigs-20100927").getFile()); }