BroadcastingEmailConverter extends AbstractConverter<BroadcastingMessageResource, Email> { @Override public Email convert(final BroadcastingMessageResource source, final Email target) { target.setTopic(source.getTopic()); target.setContent(source.getContent()); target.setAttachments(Collections.<Attachment>emptyList()); target.setCcRecipients(Collections.<Recipient>emptyList()); target.setSender(sender); target.setHtml(source.getIsHtml()); target.setRecipients(getRecipients(source)); return target; }  @Override Email convert(final BroadcastingMessageResource source, final Email target); @Override Email convert(final BroadcastingMessageResource source); void setSender(final String sender);  }
@Test public void testConvert() throws Exception { String userEmail = "email@email.email"; UserGroupView userGroup1 = new UserGroupView(); userGroup1.setUserEmail(userEmail); String content = "content"; String recipient1 = "recipient1"; String recipient2 = "recipient2"; List<String> recipient = Arrays.asList(recipient1, recipient2); Boolean isHtml = false; String topic = "topic"; BroadcastingMessageResource source = new BroadcastingMessageResource(); source.setTopic(topic); source.setContent(content); source.setRecipients(recipient); source.setIsHtml(isHtml); Recipient rec1 = new Recipient(recipient1); Recipient rec2 = new Recipient(recipient2); Recipient rec3 = new Recipient(userEmail); List<Recipient> recipients = Arrays.asList(rec3, rec2, rec1); Email expected = new Email(); expected.setTopic(source.getTopic()); expected.setContent(source.getContent()); expected.setAttachments(Collections.<Attachment>emptyList()); expected.setCcRecipients(Collections.<Recipient>emptyList()); expected.setSender(sender); expected.setHtml(source.getIsHtml()); expected.setRecipients(recipients); List<UserGroupView> userGroups = Arrays.asList(userGroup1); when(userGroupService.getUserGroupsView(anyListOf(Long.class))).thenReturn(userGroups); Email actual = unit.convert(source); assertEquals(expected, actual); }