PaperTypeResourceConverter extends AbstractConverter<PaperTypeResource, PaperType> { @Override public PaperType convert(final PaperTypeResource source, final PaperType target) { target.setName(source.getName()); target.setAbbrName(source.getAbbrName()); if (source.getPaperUsageId() != null) { PaperUsage paperUsage = new PaperUsage(); paperUsage.setId(source.getPaperUsageId()); target.setPaperUsage(paperUsage); } return target; }  @Override PaperType convert(final PaperTypeResource source, final PaperType target); @Override PaperType convert(final PaperTypeResource 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 expected = new PaperType(); expected.setName(name); expected.setAbbrName(abbrName); expected.setPaperUsage(paperUsage); PaperTypeResource source = new PaperTypeResource(); source.setName(name); source.setAbbrName(abbrName); source.setPaperUsageId(paperUsageId); PaperType actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "first blood"; String abbrName = "fb"; PaperType expected = new PaperType(); expected.setName(name); expected.setAbbrName(abbrName); PaperTypeResource source = new PaperTypeResource(); source.setName(name); source.setAbbrName(abbrName); PaperType actual = unit.convert(source); assertEquals(expected, actual); }