CheckSignatureUpdateCommand implements DroidCommand { @Override public void execute() throws CommandExecutionException { try { Map<SignatureType, SignatureFileInfo> signatureFileInfos = signatureManager.getLatestSignatureFiles(); if (signatureFileInfos.isEmpty()) { printWriter.println(I18N.getResource(I18N.CHECK_SIGNATURE_UPDATE_UNAVAILABLE)); } else { for (SignatureFileInfo sigFileInfo : signatureFileInfos.values()) { printWriter.println(I18N.getResource(I18N.CHECK_SIGNATURE_UPDATE_SUCCESS, sigFileInfo.getType(), sigFileInfo)); } } } catch (SignatureManagerException e) { throw new CommandExecutionException(I18N.getResource(I18N.CHECK_SIGNATURE_UPDATE_ERROR, e.getCause().getMessage(), e.getCauseType(), e.getCauseMessage()), e.getCause()); } }  @Override void execute(); void setSignatureManager(SignatureManager signatureManager); void setPrintWriter(PrintWriter printWriter);  }
@Test public void testCheckSignatureUpdateWhenUpdateIsAvailable() throws Exception { SignatureFileInfo sigFileInfo = new SignatureFileInfo(69, false, SignatureType.BINARY); Map<SignatureType, SignatureFileInfo> sigFiles = new HashMap<SignatureType, SignatureFileInfo>(); sigFiles.put(SignatureType.BINARY, sigFileInfo); when(signatureManager.getLatestSignatureFiles()).thenReturn(sigFiles); command.execute(); verify(printWriter).println("Binary signature update Version 69 is available"); }
@Test public void testCheckSignatureUpdateWhenNoUpdateIsAvailable() throws Exception { when(signatureManager.getLatestSignatureFiles()).thenReturn(Collections.EMPTY_MAP); command.execute(); verify(printWriter).println("No signature updates are available"); }
@Test public void testCheckSignatureUpdateWhenConnectionFails() throws SignatureManagerException { Throwable cause = new UnknownHostException("proxy"); SignatureManagerException e = new SignatureManagerException(new RuntimeException("Failed", cause)); when(signatureManager.getLatestSignatureFiles()).thenThrow(e); try { command.execute(); fail("Expected CommandExecutionEception"); } catch (CommandExecutionException cee) { assertEquals("Error checking for signature update: Failed\n" + "Caused by java.net.UnknownHostException: proxy", cee.getMessage()); } }