PersonPaperConverter extends AbstractConverter<PersonPaper, PersonPaperResource> { @Override public PersonPaperResource convert(final PersonPaper source, final PersonPaperResource target) { target.setId(source.getId()); target.setDocDate(source.getDocDate()); target.setDocIssued(source.getDocIssued()); target.setDocNum(source.getDocNum()); target.setDocPin(source.getDocPin()); target.setDocSeries(source.getDocSeries()); target.setIsChecked(source.getIsChecked()); target.setIsForeign(source.getIsForeign()); target.setMark(source.getMark()); if (source.getHonorsType() != null) { target.setHonorsTypeId(source.getHonorsType().getId()); } if (source.getPaperType() != null) { target.setPaperTypeId(source.getPaperType().getId()); } if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } return target; }  @Override PersonPaperResource convert(final PersonPaper source, final PersonPaperResource target); @Override PersonPaperResource convert(final PersonPaper source);  }
@Test public void testConvert() 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; Long honorsTypeId = 5L; HonorType honorsType = new HonorType(); honorsType.setId(honorsTypeId); Long paperTypeId = 6L; PaperType paperType = new PaperType(); paperType.setId(paperTypeId); Long personId = 7L; Person person = new Person(); person.setId(personId); PersonPaper source = new PersonPaper(); 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.setHonorsType(honorsType); source.setPaperType(paperType); source.setPerson(person); PersonPaperResource expected = new PersonPaperResource(); expected.setId(id); 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.setHonorsTypeId(honorsTypeId); expected.setPaperTypeId(paperTypeId); expected.setPersonId(personId); PersonPaperResource actual = unit.convert(source); assertEquals(expected, actual); }
@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 source = new PersonPaper(); 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); PersonPaperResource expected = new PersonPaperResource(); expected.setId(id); 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 actual = unit.convert(source); assertEquals(expected, actual); }