MessageAttributeSetters { public static void applyAll(final IObject attributes, final IObject context, final SMTPMessageAdaptor to) throws AttributeSetterException { Iterator<Map.Entry<IFieldName, Object>> iterator = attributes.iterator(); while (iterator.hasNext()) { Map.Entry<IFieldName, Object> entry = iterator.next(); try { settersMap.get(entry.getKey().toString()).setOn(to, context, entry.getValue()); } catch (NullPointerException e) { throw new AttributeSetterException("Setter not found", e); } catch (MessagingException | ReadValueException | ChangeValueException e) { throw new AttributeSetterException("Failed to set attribute", e); } } }  static void applyAll(final IObject attributes, final IObject context, final SMTPMessageAdaptor to); static void add(final String name, final MessageAttributeSetter setter);  }
@Test public void Should_MessageAttributeSettersSetMessageSubjectAndSenderSign() throws Exception { IObject context = new DSObject("{\"senderAddress\":\"some@address.ru\"}"); IObject attributes = new DSObject("{\"subject\":\"Subj.\",\"sign\":\"Author\"}"); MimeMessage mimeMessage = mock(MimeMessage.class); SMTPMessageAdaptor messageAdaptor = mock(SMTPMessageAdaptor.class); when(messageAdaptor.getMimeMessage()).thenReturn(mimeMessage); MessageAttributeSetters.applyAll(attributes, context, messageAdaptor); verify(mimeMessage).setSubject("Subj."); verify(mimeMessage).setFrom(new InternetAddress("Author<some@address.ru>")); }