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