EmailBroadcastingConverter extends AbstractConverter<Email, BroadcastingMessageResource> { @Override public BroadcastingMessageResource convert(final Email source, final BroadcastingMessageResource target) { target.setContent(source.getContent()); target.setIsHtml(source.isHtml()); target.setRecipients(getRecipients(source)); target.setTopic(source.getTopic()); return target; }  @Override BroadcastingMessageResource convert(final Email source, final BroadcastingMessageResource target); @Override BroadcastingMessageResource convert(final Email source);  }
@Test public void testConvert() throws Exception { String content = "content"; boolean isHtml = true; String email = "ivanon2@gmail.com"; String sender = "sender"; String topic = "topic"; Recipient recipient1 = new Recipient(email); List<Recipient> recipients = Arrays.asList(recipient1); Email source = new Email(); source.setContent(content); source.setHtml(isHtml); source.setRecipients(recipients); source.setSender(sender); source.setTopic(topic); List<String> recpts = Arrays.asList(email); BroadcastingMessageResource expected = new BroadcastingMessageResource(); expected.setContent(source.getContent()); expected.setIsHtml(source.isHtml()); expected.setRecipients(recpts); expected.setTopic(source.getTopic()); BroadcastingMessageResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { Email source = new Email(); BroadcastingMessageResource expected = new BroadcastingMessageResource(); expected.setRecipients(Collections.<String>emptyList()); expected.setIsHtml(false); BroadcastingMessageResource actual = unit.convert(source); assertEquals(expected, actual); }