OrderTypeConverter extends AbstractConverter<OrderType, OrderTypeResource> { @Override public OrderTypeResource convert(final OrderType source, final OrderTypeResource target) { target.setAbbrName(source.getAbbrName()); target.setId(source.getId()); target.setName(source.getName()); if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } return target; }  @Override OrderTypeResource convert(final OrderType source, final OrderTypeResource target); @Override OrderTypeResource convert(final OrderType source);  }
@Test public void testConvert() throws Exception { String abbrName = "abbrName"; String name = "name"; Long parentId = 2L; OrderType parent = new OrderType(); parent.setId(parentId); OrderType source = new OrderType(); source.setAbbrName(abbrName); source.setName(name); source.setParent(parent); OrderTypeResource expected = new OrderTypeResource(); expected.setAbbrName(abbrName); expected.setName(name); expected.setParentId(parentId); OrderTypeResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String abbrName = "abbrName"; String name = "name"; OrderType source = new OrderType(); source.setAbbrName(abbrName); source.setName(name); OrderTypeResource expected = new OrderTypeResource(); expected.setAbbrName(abbrName); expected.setName(name); OrderTypeResource actual = unit.convert(source); assertEquals(expected, actual); }