BroadcastingResourceConverter extends AbstractConverter<BroadcastingMessageResource, BroadcastingMessage> { @Override public BroadcastingMessage convert(final BroadcastingMessageResource source, final BroadcastingMessage target) { target.setContent(source.getContent()); target.setTopic(source.getTopic()); target.setRecipients(source.getRecipients()); if (source.getGroups() != null) { List<Group> groups = convertGroups(source); target.setGroups(groups); } return target; }  @Override BroadcastingMessage convert(final BroadcastingMessageResource source, final BroadcastingMessage target); @Override BroadcastingMessage convert(final BroadcastingMessageResource source);  }
@Test public void testConvert() throws Exception { String content = "content"; String topic = "topic"; String recipient1 = "recipient1@gmail.com"; String recipient2 = "recipient2@gmail.com"; List<String> recipient = Arrays.asList(recipient1, recipient2); Long groupId1 = 1L; Group group1 = new Group(); group1.setId(groupId1); Long groupId2 = 2L; Group group2 = new Group(); group2.setId(groupId2); List<Long> groupIds = Arrays.asList(groupId1, groupId2); List<Group> groups = Arrays.asList(group1, group2); BroadcastingMessageResource source = new BroadcastingMessageResource(); source.setContent(content); source.setTopic(topic); source.setRecipients(recipient); source.setGroups(groupIds); BroadcastingMessage expected = new BroadcastingMessage(); expected.setTopic(topic); expected.setContent(content); expected.setRecipients(recipient); expected.setGroups(groups); BroadcastingMessage actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { BroadcastingMessageResource source = new BroadcastingMessageResource(); BroadcastingMessage expected = new BroadcastingMessage(); BroadcastingMessage actual = unit.convert(source); assertEquals(expected, actual); }