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