@Test public void executeMessageNumberGreaterThanFolderMessageCountThrowsException() throws Exception { PowerMockito.mockStatic(SSLUtils.class); doReturn(folderMock).when(storeMock).getFolder(Matchers.anyString()); doReturn(1).when(folderMock).getMessageCount(); doReturn(true).when(folderMock).exists(); when(SSLUtils.createMessageStore(any(GetMailInput.class))).thenReturn(storeMock); inputBuilder.messageNumber("2"); try { serviceSpy.execute(inputBuilder.build()); } catch (Exception ex) { if (!(ex instanceof IndexOutOfBoundsException)) { fail(); } } }
public Map<String, String> execute(GetMailAttachmentInput getMailAttachmentInput) throws Exception { this.results = new HashMap<>(); this.input = getMailAttachmentInput; try (Store store = SSLUtils.createMessageStore(input); Folder folder = store.getFolder(input.getFolder())) { if (!folder.exists()) { throw new Exception(ExceptionMsgs.THE_SPECIFIED_FOLDER_DOES_NOT_EXIST_ON_THE_REMOTE_SERVER); } folder.open(Folder.READ_WRITE); if (input.getMessageNumber() > folder.getMessageCount()) { throw new IndexOutOfBoundsException("Message value was: " + input.getMessageNumber() + " there are only " + folder.getMessageCount() + " messages in folder"); } Message message = folder.getMessage(input.getMessageNumber()); if (input.isEncryptedMessage()) { if (Security.getProvider(SecurityConstants.BOUNCY_CASTLE_PROVIDER) == null) { Security.addProvider(new BouncyCastleProvider()); } ks = KeyStore.getInstance(SecurityConstants.PKCS_KEYSTORE_TYPE, SecurityConstants.BOUNCY_CASTLE_PROVIDER); recId = SecurityUtils.addDecryptionSettings(ks, input); } try { if (StringUtils.isEmpty(input.getDestination())) { readAttachment(message, input.getAttachmentName(), input.getCharacterSet()); } else { downloadAttachment(message, input.getAttachmentName(), input.getCharacterSet(), input.getDestination(), input.isOverwrite()); } if (input.isDeleteUponRetrieval()) { message.setFlag(Flags.Flag.DELETED, true); } results.put(io.cloudslang.content.constants.OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); } catch (UnsupportedEncodingException except) { throw new UnsupportedEncodingException("The given encoding (" + input.getCharacterSet() + ") is invalid or not supported."); } return results; } }
GetMailAttachmentService { public Map<String, String> execute(GetMailAttachmentInput getMailAttachmentInput) throws Exception { this.results = new HashMap<>(); this.input = getMailAttachmentInput; try (Store store = SSLUtils.createMessageStore(input); Folder folder = store.getFolder(input.getFolder())) { if (!folder.exists()) { throw new Exception(ExceptionMsgs.THE_SPECIFIED_FOLDER_DOES_NOT_EXIST_ON_THE_REMOTE_SERVER); } folder.open(Folder.READ_WRITE); if (input.getMessageNumber() > folder.getMessageCount()) { throw new IndexOutOfBoundsException("Message value was: " + input.getMessageNumber() + " there are only " + folder.getMessageCount() + " messages in folder"); } Message message = folder.getMessage(input.getMessageNumber()); if (input.isEncryptedMessage()) { if (Security.getProvider(SecurityConstants.BOUNCY_CASTLE_PROVIDER) == null) { Security.addProvider(new BouncyCastleProvider()); } ks = KeyStore.getInstance(SecurityConstants.PKCS_KEYSTORE_TYPE, SecurityConstants.BOUNCY_CASTLE_PROVIDER); recId = SecurityUtils.addDecryptionSettings(ks, input); } try { if (StringUtils.isEmpty(input.getDestination())) { readAttachment(message, input.getAttachmentName(), input.getCharacterSet()); } else { downloadAttachment(message, input.getAttachmentName(), input.getCharacterSet(), input.getDestination(), input.isOverwrite()); } if (input.isDeleteUponRetrieval()) { message.setFlag(Flags.Flag.DELETED, true); } results.put(io.cloudslang.content.constants.OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); } catch (UnsupportedEncodingException except) { throw new UnsupportedEncodingException("The given encoding (" + input.getCharacterSet() + ") is invalid or not supported."); } return results; } } }
GetMailAttachmentService { public Map<String, String> execute(GetMailAttachmentInput getMailAttachmentInput) throws Exception { this.results = new HashMap<>(); this.input = getMailAttachmentInput; try (Store store = SSLUtils.createMessageStore(input); Folder folder = store.getFolder(input.getFolder())) { if (!folder.exists()) { throw new Exception(ExceptionMsgs.THE_SPECIFIED_FOLDER_DOES_NOT_EXIST_ON_THE_REMOTE_SERVER); } folder.open(Folder.READ_WRITE); if (input.getMessageNumber() > folder.getMessageCount()) { throw new IndexOutOfBoundsException("Message value was: " + input.getMessageNumber() + " there are only " + folder.getMessageCount() + " messages in folder"); } Message message = folder.getMessage(input.getMessageNumber()); if (input.isEncryptedMessage()) { if (Security.getProvider(SecurityConstants.BOUNCY_CASTLE_PROVIDER) == null) { Security.addProvider(new BouncyCastleProvider()); } ks = KeyStore.getInstance(SecurityConstants.PKCS_KEYSTORE_TYPE, SecurityConstants.BOUNCY_CASTLE_PROVIDER); recId = SecurityUtils.addDecryptionSettings(ks, input); } try { if (StringUtils.isEmpty(input.getDestination())) { readAttachment(message, input.getAttachmentName(), input.getCharacterSet()); } else { downloadAttachment(message, input.getAttachmentName(), input.getCharacterSet(), input.getDestination(), input.isOverwrite()); } if (input.isDeleteUponRetrieval()) { message.setFlag(Flags.Flag.DELETED, true); } results.put(io.cloudslang.content.constants.OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); } catch (UnsupportedEncodingException except) { throw new UnsupportedEncodingException("The given encoding (" + input.getCharacterSet() + ") is invalid or not supported."); } return results; } }  }
GetMailAttachmentService { public Map<String, String> execute(GetMailAttachmentInput getMailAttachmentInput) throws Exception { this.results = new HashMap<>(); this.input = getMailAttachmentInput; try (Store store = SSLUtils.createMessageStore(input); Folder folder = store.getFolder(input.getFolder())) { if (!folder.exists()) { throw new Exception(ExceptionMsgs.THE_SPECIFIED_FOLDER_DOES_NOT_EXIST_ON_THE_REMOTE_SERVER); } folder.open(Folder.READ_WRITE); if (input.getMessageNumber() > folder.getMessageCount()) { throw new IndexOutOfBoundsException("Message value was: " + input.getMessageNumber() + " there are only " + folder.getMessageCount() + " messages in folder"); } Message message = folder.getMessage(input.getMessageNumber()); if (input.isEncryptedMessage()) { if (Security.getProvider(SecurityConstants.BOUNCY_CASTLE_PROVIDER) == null) { Security.addProvider(new BouncyCastleProvider()); } ks = KeyStore.getInstance(SecurityConstants.PKCS_KEYSTORE_TYPE, SecurityConstants.BOUNCY_CASTLE_PROVIDER); recId = SecurityUtils.addDecryptionSettings(ks, input); } try { if (StringUtils.isEmpty(input.getDestination())) { readAttachment(message, input.getAttachmentName(), input.getCharacterSet()); } else { downloadAttachment(message, input.getAttachmentName(), input.getCharacterSet(), input.getDestination(), input.isOverwrite()); } if (input.isDeleteUponRetrieval()) { message.setFlag(Flags.Flag.DELETED, true); } results.put(io.cloudslang.content.constants.OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); } catch (UnsupportedEncodingException except) { throw new UnsupportedEncodingException("The given encoding (" + input.getCharacterSet() + ") is invalid or not supported."); } return results; } }  Map<String, String> execute(GetMailAttachmentInput getMailAttachmentInput); }
GetMailAttachmentService { public Map<String, String> execute(GetMailAttachmentInput getMailAttachmentInput) throws Exception { this.results = new HashMap<>(); this.input = getMailAttachmentInput; try (Store store = SSLUtils.createMessageStore(input); Folder folder = store.getFolder(input.getFolder())) { if (!folder.exists()) { throw new Exception(ExceptionMsgs.THE_SPECIFIED_FOLDER_DOES_NOT_EXIST_ON_THE_REMOTE_SERVER); } folder.open(Folder.READ_WRITE); if (input.getMessageNumber() > folder.getMessageCount()) { throw new IndexOutOfBoundsException("Message value was: " + input.getMessageNumber() + " there are only " + folder.getMessageCount() + " messages in folder"); } Message message = folder.getMessage(input.getMessageNumber()); if (input.isEncryptedMessage()) { if (Security.getProvider(SecurityConstants.BOUNCY_CASTLE_PROVIDER) == null) { Security.addProvider(new BouncyCastleProvider()); } ks = KeyStore.getInstance(SecurityConstants.PKCS_KEYSTORE_TYPE, SecurityConstants.BOUNCY_CASTLE_PROVIDER); recId = SecurityUtils.addDecryptionSettings(ks, input); } try { if (StringUtils.isEmpty(input.getDestination())) { readAttachment(message, input.getAttachmentName(), input.getCharacterSet()); } else { downloadAttachment(message, input.getAttachmentName(), input.getCharacterSet(), input.getDestination(), input.isOverwrite()); } if (input.isDeleteUponRetrieval()) { message.setFlag(Flags.Flag.DELETED, true); } results.put(io.cloudslang.content.constants.OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); } catch (UnsupportedEncodingException except) { throw new UnsupportedEncodingException("The given encoding (" + input.getCharacterSet() + ") is invalid or not supported."); } return results; } }  Map<String, String> execute(GetMailAttachmentInput getMailAttachmentInput);  }