PersonPaperResourceConverter extends AbstractConverter<PersonPaperResource, PersonPaper> { @Override public PersonPaper convert(final PersonPaperResource source, final PersonPaper target) { if (source.getPersonId() != null) { Person person = new Person(); person.setId(source.getPersonId()); target.setPerson(person); } if (source.getPaperTypeId() != null) { PaperType paperType = new PaperType(); paperType.setId(source.getPaperTypeId()); target.setPaperType(paperType); } if (source.getHonorsTypeId() != null) { HonorType honorsType = new HonorType(); honorsType.setId(source.getHonorsTypeId()); target.setHonorsType(honorsType); } target.setDocSeries(source.getDocSeries()); target.setDocNum(source.getDocNum()); target.setDocDate(source.getDocDate()); target.setDocIssued(source.getDocIssued()); target.setDocPin(source.getDocPin()); target.setMark(source.getMark()); target.setIsChecked(source.getIsChecked()); target.setIsForeign(source.getIsForeign()); return target; }  @Override PersonPaper convert(final PersonPaperResource source, final PersonPaper target); @Override PersonPaper convert(final PersonPaperResource source);  }
@Test public void testConvert() throws Exception { Long honorsTypeId = 1L; HonorType honorsType = new HonorType(); honorsType.setId(honorsTypeId); Long paperTypeId = 2L; PaperType paperType = new PaperType(); paperType.setId(paperTypeId); Long personId = 3L; Person person = new Person(); person.setId(personId); Long id = 4L; Date docDate = new Date(); String docIssued = "doc issued"; String docNum = "doc num"; String docPin = "doc pint"; String docSeries = "doc series"; Integer isChecked = 1; Integer isForeign = 0; Double mark = 2.0; PersonPaper expected = new PersonPaper(); expected.setDocDate(docDate); expected.setDocIssued(docIssued); expected.setDocNum(docNum); expected.setDocPin(docPin); expected.setDocSeries(docSeries); expected.setIsChecked(isChecked); expected.setIsForeign(isForeign); expected.setMark(mark); expected.setHonorsType(honorsType); expected.setPaperType(paperType); expected.setPerson(person); PersonPaperResource source = new PersonPaperResource(); source.setId(id); source.setDocDate(docDate); source.setDocIssued(docIssued); source.setDocNum(docNum); source.setDocPin(docPin); source.setDocSeries(docSeries); source.setIsChecked(isChecked); source.setIsForeign(isForeign); source.setMark(mark); source.setHonorsTypeId(honorsTypeId); source.setPaperTypeId(paperTypeId); source.setPersonId(personId); PersonPaper actual = unit.convert(source); assertEquals(expected.toString(), actual.toString()); }
@Test public void testConvertWithNoRelations() throws Exception { Long id = 4L; Date docDate = new Date(); String docIssued = "doc issued"; String docNum = "doc num"; String docPin = "doc pint"; String docSeries = "doc series"; Integer isChecked = 1; Integer isForeign = 0; Double mark = 2.0; PersonPaper expected = new PersonPaper(); expected.setDocDate(docDate); expected.setDocIssued(docIssued); expected.setDocNum(docNum); expected.setDocPin(docPin); expected.setDocSeries(docSeries); expected.setIsChecked(isChecked); expected.setIsForeign(isForeign); expected.setMark(mark); PersonPaperResource source = new PersonPaperResource(); source.setId(id); source.setDocDate(docDate); source.setDocIssued(docIssued); source.setDocNum(docNum); source.setDocPin(docPin); source.setDocSeries(docSeries); source.setIsChecked(isChecked); source.setIsForeign(isForeign); source.setMark(mark); PersonPaper actual = unit.convert(source); assertEquals(expected.toString(), actual.toString()); }