AssetConverter extends AbstractConverter<Asset, AssetResource> { @Override public AssetResource convert(final Asset source, final AssetResource target) { target.setId(source.getId()); target.setAmount(source.getAmount()); target.setBegDate(source.getBegDate()); target.setDescription(source.getDescription()); target.setEndDate(source.getEndDate()); target.setInvNum(source.getInvNum()); target.setName(source.getName()); target.setPrice(source.getPrice()); target.setProdDate(source.getProdDate()); target.setSerialNum(source.getSerialNum()); target.setSuma(source.getSuma()); if (source.getPartner() != null) { target.setPartnerId(source.getPartner().getId()); } if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } if (source.getOrder() != null) { target.setOrderId(source.getOrder().getId()); } if (source.getEmployee() != null) { target.setEmployeeId(source.getEmployee().getId()); } if (source.getDepartment() != null) { target.setDepartmentId(source.getDepartment().getId()); } if (source.getAssetType() != null) { target.setAssetTypeId(source.getAssetType().getId()); } if (source.getAssetStatus() != null) { target.setAssetStatusId(source.getAssetStatus().getId()); } if (source.getAssetState() != null) { target.setAssetStateId(source.getAssetState().getId()); } return target; }  @Override AssetResource convert(final Asset source, final AssetResource target); @Override AssetResource convert(final Asset source);  }
@Test public void testConvert() throws Exception { Long id = 11L; Long assetStatusId = 2L; Long assetTypeId = 3L; Long departmentId = 4L; Long employeeId = 5L; Long orderId = 6L; Long parentId = 7L; Long partnerId = 8L; Date begDate = new Date(); Date endDate = new Date(); Date prodDate = new Date(); Double amount = 2.0; Double price = 1241.0; Double suma = 242.0; String description = "description"; String invNum = "invNum"; String name = "name"; String serialNum = "serial num"; AssetState assetState = new AssetState(); Long assetStateId = 1L; assetState.setId(assetStateId); AssetStatus assetStatus = new AssetStatus(); assetStatus.setId(assetStatusId); AssetType assetType = new AssetType(); assetType.setId(assetTypeId); Department department = new Department(); department.setId(departmentId); Employee employee = new Employee(); employee.setId(employeeId); Order order = new Order(); order.setId(orderId); Asset parent = new Asset(); parent.setId(parentId); Partner partner = new Partner(); partner.setId(partnerId); Asset source = new Asset(); source.setAmount(amount); source.setAssetState(assetState); source.setAssetStatus(assetStatus); source.setAssetType(assetType); source.setBegDate(begDate); source.setDepartment(department); source.setDescription(description); source.setEmployee(employee); source.setEndDate(endDate); source.setId(id); source.setInvNum(invNum); source.setName(name); source.setOrder(order); source.setParent(parent); source.setPartner(partner); source.setPrice(price); source.setProdDate(prodDate); source.setSerialNum(serialNum); source.setSuma(suma); AssetResource expected = new AssetResource(); expected.setAmount(amount); expected.setAssetStateId(assetStateId); expected.setAssetStatusId(assetStatusId); expected.setAssetTypeId(assetTypeId); expected.setBegDate(begDate); expected.setDepartmentId(departmentId); expected.setDescription(description); expected.setEmployeeId(employeeId); expected.setEndDate(endDate); expected.setId(id); expected.setInvNum(invNum); expected.setName(name); expected.setOrderId(orderId); expected.setParentId(parentId); expected.setPartnerId(partnerId); expected.setPrice(price); expected.setProdDate(prodDate); expected.setSerialNum(serialNum); expected.setSuma(suma); AssetResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Long id = 11L; Date begDate = new Date(); Date endDate = new Date(); Date prodDate = new Date(); Double amount = 2.0; Double price = 1241.0; Double suma = 242.0; String description = "description"; String invNum = "invNum"; String name = "name"; String serialNum = "serial num"; Asset source = new Asset(); source.setAmount(amount); source.setBegDate(begDate); source.setDescription(description); source.setEndDate(endDate); source.setId(id); source.setInvNum(invNum); source.setName(name); source.setPrice(price); source.setProdDate(prodDate); source.setSerialNum(serialNum); source.setSuma(suma); AssetResource expected = new AssetResource(); expected.setAmount(amount); expected.setBegDate(begDate); expected.setDescription(description); expected.setEndDate(endDate); expected.setId(id); expected.setInvNum(invNum); expected.setName(name); expected.setPrice(price); expected.setProdDate(prodDate); expected.setSerialNum(serialNum); expected.setSuma(suma); AssetResource actual = unit.convert(source); assertEquals(expected, actual); }