@Test public void testAddHeadersToSMTPMessageThrowsException() throws MessagingException { ArrayList<String> headerNames = new ArrayList<>(); headerNames.add(0, "Sensitivity"); ArrayList<String> headerValues = new ArrayList<>(); headerValues.add(0, "Company-Confidential"); Mockito.when(new SMTPMessage(smtpMessageMock)).thenReturn(msgMock); doThrow(new MessagingException()).when(msgMock).getHeader(Matchers.anyString()); exception.expect(MessagingException.class); sendMailService.addHeadersToSMTPMessage(smtpMessageMock, headerNames, headerValues); }
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);  }