AdminUnitConverter extends AbstractConverter<AdminUnit, AdminUnitResource> { @Override public AdminUnitResource convert(final AdminUnit source, final AdminUnitResource target) { target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); target.setId(source.getId()); target.setIdentifier(source.getIdentifier()); target.setIdentifier1(source.getIdentifier1()); target.setIdentifier2(source.getIdentifier2()); target.setIdentifier3(source.getIdentifier3()); target.setName(source.getName()); if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } if (source.getAdminUnitType() != null) { target.setAdminUnitTypeId(source.getAdminUnitType().getId()); } return target; }  @Override AdminUnitResource convert(final AdminUnit source, final AdminUnitResource target); @Override AdminUnitResource convert(final AdminUnit source);  }
@Test public void testConvert() throws Exception { Long parentId = 2L; AdminUnit parent = new AdminUnit(); parent.setId(parentId); Long adminUnitTypeId = 3L; AdminUnitType adminUnitType = new AdminUnitType(); adminUnitType.setId(adminUnitTypeId); Date begDate = new Date(); Date endDate = new Date(); Long id = 1L; String identifier = "identifier"; String identifier1 = "identifier1"; String identifier2 = "identifier2"; String identifier3 = "identifier3"; String name = "name1"; AdminUnit source = new AdminUnit(); source.setBegDate(begDate); source.setEndDate(endDate); source.setId(id); source.setIdentifier(identifier); source.setIdentifier1(identifier1); source.setIdentifier2(identifier2); source.setIdentifier3(identifier3); source.setName(name); source.setParent(parent); source.setAdminUnitType(adminUnitType); AdminUnitResource expected = new AdminUnitResource(); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setId(id); expected.setIdentifier(identifier); expected.setIdentifier1(identifier1); expected.setIdentifier2(identifier2); expected.setIdentifier3(identifier3); expected.setName(name); expected.setParentId(parentId); expected.setAdminUnitTypeId(adminUnitTypeId); AdminUnitResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Date begDate = new Date(); Date endDate = new Date(); Long id = 1L; String identifier = "identifier"; String identifier1 = "identifier1"; String identifier2 = "identifier2"; String identifier3 = "identifier3"; String name = "name1"; AdminUnit source = new AdminUnit(); source.setBegDate(begDate); source.setEndDate(endDate); source.setId(id); source.setIdentifier(identifier); source.setIdentifier1(identifier1); source.setIdentifier2(identifier2); source.setIdentifier3(identifier3); source.setName(name); AdminUnitResource expected = new AdminUnitResource(); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setId(id); expected.setIdentifier(identifier); expected.setIdentifier1(identifier1); expected.setIdentifier2(identifier2); expected.setIdentifier3(identifier3); expected.setName(name); AdminUnitResource actual = unit.convert(source); assertEquals(expected, actual); }