PaperTypeConverter extends AbstractConverter<PaperType, PaperTypeResource> { @Override public PaperTypeResource convert(final PaperType source, final PaperTypeResource target) { target.setId(source.getId()); target.setName(source.getName()); target.setAbbrName(source.getAbbrName()); if (source.getPaperUsage() != null) { target.setPaperUsageId(source.getPaperUsage().getId()); } return target; }  @Override PaperTypeResource convert(final PaperType source, final PaperTypeResource target); @Override PaperTypeResource convert(final PaperType source);  }
@Test public void testConvert() throws Exception { String name = "first blood"; String abbrName = "fb"; Long paperUsageId = 2L; PaperUsage paperUsage = new PaperUsage(); paperUsage.setId(paperUsageId); PaperType source = new PaperType(); source.setName(name); source.setAbbrName(abbrName); source.setPaperUsage(paperUsage); PaperTypeResource expected = new PaperTypeResource(); expected.setName(name); expected.setAbbrName(abbrName); expected.setPaperUsageId(paperUsageId); PaperTypeResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "first blood"; String abbrName = "fb"; PaperType source = new PaperType(); source.setName(name); source.setAbbrName(abbrName); PaperTypeResource expected = new PaperTypeResource(); expected.setName(name); expected.setAbbrName(abbrName); PaperTypeResource actual = unit.convert(source); assertEquals(expected, actual); }