@Test public void testAddHeadersToSMTPMessage() throws MessagingException { ArrayList<String> headerNames = new ArrayList<>(); headerNames.add(0, "Sensitivity"); headerNames.add(1, "message-type"); headerNames.add(2, "Sensitivity"); ArrayList<String> headerValues = new ArrayList<>(); headerValues.add(0, "Company-Confidential"); headerValues.add(1, "Multiple Part"); headerValues.add(2, "Personal"); doReturn(null).doReturn(new String[]{"Company-Confidential"}).when(msgMock).getHeader("Sensitivity"); Mockito.when(new SMTPMessage(smtpMessageMock)).thenReturn(msgMock); sendMailService.addHeadersToSMTPMessage(smtpMessageMock, headerNames, headerValues); verify(msgMock, times(1)).addHeader(Matchers.anyString(), Matchers.anyString()); verify(msgMock, times(2)).setHeader(Matchers.anyString(), Matchers.anyString()); verify(msgMock, times(3)).getHeader(Matchers.anyString()); }
protected SMTPMessage addHeadersToSMTPMessage(SMTPMessage message, List<String> headerNames, List<String> headerValues) throws MessagingException { SMTPMessage msg = new SMTPMessage(message); Iterator namesIter = headerNames.iterator(); Iterator valuesIter = headerValues.iterator(); while (namesIter.hasNext() && valuesIter.hasNext()) { String headerName = (String) namesIter.next(); String headerValue = (String) valuesIter.next(); if (msg.getHeader(headerName) != null) { msg.addHeader(headerName, headerValue); } else { msg.setHeader(headerName, headerValue); } } return msg; }
SendMailService { protected SMTPMessage addHeadersToSMTPMessage(SMTPMessage message, List<String> headerNames, List<String> headerValues) throws MessagingException { SMTPMessage msg = new SMTPMessage(message); Iterator namesIter = headerNames.iterator(); Iterator valuesIter = headerValues.iterator(); while (namesIter.hasNext() && valuesIter.hasNext()) { String headerName = (String) namesIter.next(); String headerValue = (String) valuesIter.next(); if (msg.getHeader(headerName) != null) { msg.addHeader(headerName, headerValue); } else { msg.setHeader(headerName, headerValue); } } return msg; } }
SendMailService { protected SMTPMessage addHeadersToSMTPMessage(SMTPMessage message, List<String> headerNames, List<String> headerValues) throws MessagingException { SMTPMessage msg = new SMTPMessage(message); Iterator namesIter = headerNames.iterator(); Iterator valuesIter = headerValues.iterator(); while (namesIter.hasNext() && valuesIter.hasNext()) { String headerName = (String) namesIter.next(); String headerValue = (String) valuesIter.next(); if (msg.getHeader(headerName) != null) { msg.addHeader(headerName, headerValue); } else { msg.setHeader(headerName, headerValue); } } return msg; }  }
SendMailService { protected SMTPMessage addHeadersToSMTPMessage(SMTPMessage message, List<String> headerNames, List<String> headerValues) throws MessagingException { SMTPMessage msg = new SMTPMessage(message); Iterator namesIter = headerNames.iterator(); Iterator valuesIter = headerValues.iterator(); while (namesIter.hasNext() && valuesIter.hasNext()) { String headerName = (String) namesIter.next(); String headerValue = (String) valuesIter.next(); if (msg.getHeader(headerName) != null) { msg.addHeader(headerName, headerValue); } else { msg.setHeader(headerName, headerValue); } } return msg; }  Map<String, String> execute(SendMailInput sendMailInput); }
SendMailService { protected SMTPMessage addHeadersToSMTPMessage(SMTPMessage message, List<String> headerNames, List<String> headerValues) throws MessagingException { SMTPMessage msg = new SMTPMessage(message); Iterator namesIter = headerNames.iterator(); Iterator valuesIter = headerValues.iterator(); while (namesIter.hasNext() && valuesIter.hasNext()) { String headerName = (String) namesIter.next(); String headerValue = (String) valuesIter.next(); if (msg.getHeader(headerName) != null) { msg.addHeader(headerName, headerValue); } else { msg.setHeader(headerName, headerValue); } } return msg; }  Map<String, String> execute(SendMailInput sendMailInput);  }