@Test public void testExecute() throws Exception { doReturn(3).when(folderMock).getMessageCount(); doReturn(true).when(folderMock).exists(); doNothing().when(folderMock).open(Matchers.anyInt()); doReturn(folderMock).when(storeMock).getFolder(Matchers.anyString()); doNothing().when(storeMock).connect(); PowerMockito.mockStatic(SSLUtils.class); when(SSLUtils.createMessageStore(any(GetMailInput.class))).thenCallRealMethod(); when(SSLUtils.tryTLSOtherwiseTrySSL(any(SimpleAuthenticator.class), any(Properties.class), any(GetMailInput.class))).thenCallRealMethod(); when(SSLUtils.configureStoreWithTLS(any(Properties.class), any(SimpleAuthenticator.class), any(GetMailInput.class))).thenReturn(storeMock); when(SSLUtils.configureStoreWithSSL(any(Properties.class), any(SimpleAuthenticator.class), any(GetMailInput.class))).thenReturn(storeMock); PowerMockito.doNothing().when(SSLUtils.class, "addSSLSettings", anyBoolean(), anyString(), anyString(), anyString(), anyString()); inputBuilder.enableTLS(String.valueOf(true)); Map<String, String> results = serviceSpy.execute(inputBuilder.build()); assertEquals(results.get(OutputNames.RETURN_RESULT), "3"); }
public Map<String, String> execute(GetMailMessageCountInput getMailMessageCountInput) throws Exception { this.results = new HashMap<>(); this.input = getMailMessageCountInput; 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_ONLY); results.put(OutputNames.RETURN_RESULT, String.valueOf(folder.getMessageCount())); results.put(OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); return results; } }
GetMailMessageCountService { public Map<String, String> execute(GetMailMessageCountInput getMailMessageCountInput) throws Exception { this.results = new HashMap<>(); this.input = getMailMessageCountInput; 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_ONLY); results.put(OutputNames.RETURN_RESULT, String.valueOf(folder.getMessageCount())); results.put(OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); return results; } } }
GetMailMessageCountService { public Map<String, String> execute(GetMailMessageCountInput getMailMessageCountInput) throws Exception { this.results = new HashMap<>(); this.input = getMailMessageCountInput; 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_ONLY); results.put(OutputNames.RETURN_RESULT, String.valueOf(folder.getMessageCount())); results.put(OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); return results; } }  }
GetMailMessageCountService { public Map<String, String> execute(GetMailMessageCountInput getMailMessageCountInput) throws Exception { this.results = new HashMap<>(); this.input = getMailMessageCountInput; 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_ONLY); results.put(OutputNames.RETURN_RESULT, String.valueOf(folder.getMessageCount())); results.put(OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); return results; } }  Map<String, String> execute(GetMailMessageCountInput getMailMessageCountInput); }
GetMailMessageCountService { public Map<String, String> execute(GetMailMessageCountInput getMailMessageCountInput) throws Exception { this.results = new HashMap<>(); this.input = getMailMessageCountInput; 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_ONLY); results.put(OutputNames.RETURN_RESULT, String.valueOf(folder.getMessageCount())); results.put(OutputNames.RETURN_CODE, ReturnCodes.SUCCESS); return results; } }  Map<String, String> execute(GetMailMessageCountInput getMailMessageCountInput);  }