SubjectConverter extends AbstractConverter<Subject, SubjectResource> { @Override public SubjectResource convert(final Subject source, final SubjectResource target) { target.setId(source.getId()); target.setName(source.getName()); if (source.getSubjectType() != null) { target.setSubjectTypeId(source.getSubjectType().getId()); } return target; }  @Override SubjectResource convert(final Subject source, final SubjectResource target); @Override SubjectResource convert(final Subject source);  }
@Test public void testConvert() throws Exception { String name = "first blood"; Long subjectTypeId = 1L; SubjectType subjectType = new SubjectType(); subjectType.setId(subjectTypeId); Subject source = new Subject(); source.setName(name); source.setSubjectType(subjectType); SubjectResource expected = new SubjectResource(); expected.setName(name); expected.setSubjectTypeId(subjectTypeId); SubjectResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "first blood"; Subject source = new Subject(); source.setName(name); SubjectResource expected = new SubjectResource(); expected.setName(name); SubjectResource actual = unit.convert(source); assertEquals(expected, actual); }