PersonAwardResourceConverter extends AbstractConverter<PersonAwardResource, PersonAward> { @Override public PersonAward convert(final PersonAwardResource source, final PersonAward target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getPersonPaperId() != null) { PersonPaper paper = new PersonPaper(); paper.setId(source.getPersonPaperId()); target.setPersonPaper(paper); } if (source.getPublicActivityAwardId() != null) { PublicActivityAward award = new PublicActivityAward(); award.setId(source.getPublicActivityAwardId()); target.setPublicActivityAward(award); } target.setBonus(source.getBonus()); return target; }  @Override PersonAward convert(final PersonAwardResource source, final PersonAward target); @Override PersonAward convert(final PersonAwardResource source);  }
@Test public void testConvert() throws Exception { Long id = 1L; Double bonus = 2.0; 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);; PersonAward expected = new PersonAward(); expected.setBonus(bonus); expected.setId(id); expected.setPerson(person); expected.setPersonPaper(personPaper); expected.setPublicActivityAward(publicActivityAward); PersonAwardResource source = new PersonAwardResource(); source.setId(id); source.setPersonId(personId); source.setPersonPaperId(personPaperId); source.setPublicActivityAwardId(publicActivityAwardId); source.setBonus(bonus); PersonAward actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Long id = 1L; Double bonus = 2.0; PersonAward expected = new PersonAward(); expected.setBonus(bonus); expected.setId(id); PersonAwardResource source = new PersonAwardResource(); source.setId(id); source.setBonus(bonus); PersonAward actual = unit.convert(source); assertEquals(expected, actual); }