PersonAwardConverter extends AbstractConverter<PersonAward, PersonAwardResource> { @Override public PersonAwardResource convert(final PersonAward source, final PersonAwardResource target) { target.setBonus(source.getBonus()); target.setId(source.getId()); if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getPersonPaper() != null) { target.setPersonPaperId(source.getPersonPaper().getId()); } if (source.getPublicActivityAward() != null) { target.setPublicActivityAwardId(source.getPublicActivityAward().getId()); } return target; }  @Override PersonAwardResource convert(final PersonAward source, final PersonAwardResource target); @Override PersonAwardResource convert(final PersonAward source);  }
@Test public void testConvert() throws Exception { Long id = 1L; Double bonus = 2.0; PersonAward source = new PersonAward(); Long personId = 2L; Person person = new Person(); person.setId(personId); Long personPaperId = 3L; PersonPaper personPaper = new PersonPaper(); personPaper.setId(personPaperId); Long publicActivityAwardId = 4L; PublicActivityAward publicActivityAward = new PublicActivityAward(); publicActivityAward.setId(publicActivityAwardId);; source.setBonus(bonus); source.setId(id); source.setPerson(person); source.setPersonPaper(personPaper); source.setPublicActivityAward(publicActivityAward); PersonAwardResource expected = new PersonAwardResource(); expected.setId(id); expected.setPersonId(personId); expected.setPersonPaperId(personPaperId); expected.setPublicActivityAwardId(publicActivityAwardId); expected.setBonus(bonus); PersonAwardResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Long id = 1L; Double bonus = 2.0; PersonAward source = new PersonAward(); source.setBonus(bonus); source.setId(id); PersonAwardResource expected = new PersonAwardResource(); expected.setId(id); expected.setBonus(bonus); PersonAwardResource actual = unit.convert(source); assertEquals(expected, actual); }