DegreeResourceConverter extends AbstractConverter<DegreeResource, Degree> { @Override public Degree convert(final DegreeResource source, final Degree target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getDegreeTypeId() != null) { DegreeType degreeType = new DegreeType(); degreeType.setId(source.getDegreeTypeId()); target.setDegreeType(degreeType); } return target; }  @Override Degree convert(final DegreeResource source, final Degree target); @Override Degree convert(final DegreeResource source);  }
@Test public void testConvert() throws Exception { Long personId = 1L; Long degreeTypeId = 2L; DegreeResource source = new DegreeResource(); source.setPersonId(personId); source.setDegreeTypeId(degreeTypeId); Person person = new Person(); person.setId(personId); DegreeType degreeType = new DegreeType(); degreeType.setId(degreeTypeId); Degree expected = new Degree(); expected.setPerson(person); expected.setDegreeType(degreeType); Degree actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithEmptyFields() throws Exception { DegreeResource source = new DegreeResource(); Degree expected = new Degree(); Degree actual = unit.convert(source); assertEquals(expected, actual); }