SignatureManagerImpl implements SignatureManager { @Override public Map<SignatureType, SignatureFileInfo> getDefaultSignatures() throws SignatureFileException { Map<SignatureType, SignatureFileInfo> defaultSignatures = new HashMap<SignatureType, SignatureFileInfo>(); final Map<SignatureType, SortedMap<String, SignatureFileInfo>> availableSignatureFiles = getAvailableSignatureFiles(); final String errorMessagePattern = "Default signature file %s could not be found. Please check your signature settings."; for (Map.Entry<SignatureType, SortedMap<String, SignatureFileInfo>> sigFileEntry : availableSignatureFiles.entrySet()) { SignatureType type = sigFileEntry.getKey(); Map<String, SignatureFileInfo> sigs = sigFileEntry.getValue(); DroidGlobalProperty defaultSigFile = defaultVersionProperties.get(type); String defaultSigFileKey = config.getProperties().getString(defaultSigFile.getName()); if (StringUtils.isNotBlank(defaultSigFileKey)) { SignatureFileInfo sigFileInfo = sigs.get(defaultSigFileKey); if (sigFileInfo == null) { String errorMessage = String.format(errorMessagePattern, config.getProperties() .getString(defaultVersionProperties.get(type).getName())); throw new SignatureFileException(errorMessage, ErrorCode.FILE_NOT_FOUND); } defaultSignatures.put(type, sigFileInfo); } } return defaultSignatures; } 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 testGetDefaultContainerSignature() throws Exception { final Path containerSigFile1 = containerSigFileDir.resolve("container_sigs-20100927.xml"); final Path containerSigFile2 = containerSigFileDir.resolve("container_sigs-20100827.xml"); final Path textSigFile1 = textSigFileDir.resolve("text_sigs-20110927.xml"); final Path textSigFile2 = textSigFileDir.resolve("text_sigs-20110827.xml"); Files.createFile(containerSigFile1); Files.createFile(containerSigFile2); Files.createFile(textSigFile1); Files.createFile(textSigFile2); assertTrue(Files.exists(containerSigFile1)); assertTrue(Files.exists(containerSigFile2)); assertTrue(Files.exists(textSigFile1)); assertTrue(Files.exists(textSigFile2)); when(configuration.getString(DroidGlobalProperty.DEFAULT_BINARY_SIG_FILE_VERSION.getName())) .thenReturn("DROID_SignatureFile_V26"); when(configuration.getString(DroidGlobalProperty.DEFAULT_CONTAINER_SIG_FILE_VERSION.getName())) .thenReturn("container_sigs-20100927"); when(configuration.getString(DroidGlobalProperty.DEFAULT_TEXT_SIG_FILE_VERSION.getName())) .thenReturn("text_sigs-20110827"); SignatureFileInfo sigInfo = signatureManager.getDefaultSignatures().get(SignatureType.CONTAINER); assertEquals(containerSigFileDir.resolve("container_sigs-20100927.xml"), sigInfo.getFile()); assertEquals(20100927, sigInfo.getVersion()); }