@Test public void shouldFillProductInfoFromRequisitionIfLineItemExists() throws Exception { ShipmentLineItem shipmentLineItem = spy(make(a(defaultShipmentLineItem, with(productCode, "P10"), with(orderId, 1L), with(quantityShipped, 20)))); shipmentLineItem.setReplacedProductCode(null); RnrLineItem lineItem = make(a(defaultRnrLineItem)); when(requisitionService.getNonSkippedLineItem(shipmentLineItem.getOrderId(), "P10")).thenReturn(lineItem); when(productService.getByCode(shipmentLineItem.getProductCode())).thenReturn(new Product()); shipmentService.save(shipmentLineItem); verify(shipmentLineItem).fillReferenceFields(lineItem); }
public void save(ShipmentLineItem shipmentLineItem) { if (shipmentLineItem.getQuantityShipped() < 0) { throw new DataException("error.negative.shipped.quantity"); } RnrLineItem lineItem; if ((lineItem = requisitionService.getNonSkippedLineItem(shipmentLineItem.getOrderId(), shipmentLineItem.getProductCode())) != null) { shipmentLineItem.fillReferenceFields(lineItem); } else { Product product = productService.getByCode(shipmentLineItem.getProductCode()); if (product == null) { throw new DataException("error.unknown.product"); } Long programId = requisitionService.getProgramId(shipmentLineItem.getOrderId()); ProgramProduct programProduct = programProductService.getByProgramAndProductId(programId, product.getId()); if (programProduct != null) { programProduct.setProduct(product); shipmentLineItem.fillReferenceFields(programProduct); } else { shipmentLineItem.fillReferenceFields(product); } } if (shipmentLineItem.getReplacedProductCode() != null) { if (productService.getByCode(shipmentLineItem.getReplacedProductCode()) == null) { throw new DataException("error.unknown.product"); } } shipmentRepository.save(shipmentLineItem); }
ShipmentService { public void save(ShipmentLineItem shipmentLineItem) { if (shipmentLineItem.getQuantityShipped() < 0) { throw new DataException("error.negative.shipped.quantity"); } RnrLineItem lineItem; if ((lineItem = requisitionService.getNonSkippedLineItem(shipmentLineItem.getOrderId(), shipmentLineItem.getProductCode())) != null) { shipmentLineItem.fillReferenceFields(lineItem); } else { Product product = productService.getByCode(shipmentLineItem.getProductCode()); if (product == null) { throw new DataException("error.unknown.product"); } Long programId = requisitionService.getProgramId(shipmentLineItem.getOrderId()); ProgramProduct programProduct = programProductService.getByProgramAndProductId(programId, product.getId()); if (programProduct != null) { programProduct.setProduct(product); shipmentLineItem.fillReferenceFields(programProduct); } else { shipmentLineItem.fillReferenceFields(product); } } if (shipmentLineItem.getReplacedProductCode() != null) { if (productService.getByCode(shipmentLineItem.getReplacedProductCode()) == null) { throw new DataException("error.unknown.product"); } } shipmentRepository.save(shipmentLineItem); } }
ShipmentService { public void save(ShipmentLineItem shipmentLineItem) { if (shipmentLineItem.getQuantityShipped() < 0) { throw new DataException("error.negative.shipped.quantity"); } RnrLineItem lineItem; if ((lineItem = requisitionService.getNonSkippedLineItem(shipmentLineItem.getOrderId(), shipmentLineItem.getProductCode())) != null) { shipmentLineItem.fillReferenceFields(lineItem); } else { Product product = productService.getByCode(shipmentLineItem.getProductCode()); if (product == null) { throw new DataException("error.unknown.product"); } Long programId = requisitionService.getProgramId(shipmentLineItem.getOrderId()); ProgramProduct programProduct = programProductService.getByProgramAndProductId(programId, product.getId()); if (programProduct != null) { programProduct.setProduct(product); shipmentLineItem.fillReferenceFields(programProduct); } else { shipmentLineItem.fillReferenceFields(product); } } if (shipmentLineItem.getReplacedProductCode() != null) { if (productService.getByCode(shipmentLineItem.getReplacedProductCode()) == null) { throw new DataException("error.unknown.product"); } } shipmentRepository.save(shipmentLineItem); }  }
ShipmentService { public void save(ShipmentLineItem shipmentLineItem) { if (shipmentLineItem.getQuantityShipped() < 0) { throw new DataException("error.negative.shipped.quantity"); } RnrLineItem lineItem; if ((lineItem = requisitionService.getNonSkippedLineItem(shipmentLineItem.getOrderId(), shipmentLineItem.getProductCode())) != null) { shipmentLineItem.fillReferenceFields(lineItem); } else { Product product = productService.getByCode(shipmentLineItem.getProductCode()); if (product == null) { throw new DataException("error.unknown.product"); } Long programId = requisitionService.getProgramId(shipmentLineItem.getOrderId()); ProgramProduct programProduct = programProductService.getByProgramAndProductId(programId, product.getId()); if (programProduct != null) { programProduct.setProduct(product); shipmentLineItem.fillReferenceFields(programProduct); } else { shipmentLineItem.fillReferenceFields(product); } } if (shipmentLineItem.getReplacedProductCode() != null) { if (productService.getByCode(shipmentLineItem.getReplacedProductCode()) == null) { throw new DataException("error.unknown.product"); } } shipmentRepository.save(shipmentLineItem); }  void save(ShipmentLineItem shipmentLineItem); void insertShipmentFileInfo(ShipmentFileInfo shipmentFileInfo); List<ShipmentLineItem> getLineItems(long orderId); }
ShipmentService { public void save(ShipmentLineItem shipmentLineItem) { if (shipmentLineItem.getQuantityShipped() < 0) { throw new DataException("error.negative.shipped.quantity"); } RnrLineItem lineItem; if ((lineItem = requisitionService.getNonSkippedLineItem(shipmentLineItem.getOrderId(), shipmentLineItem.getProductCode())) != null) { shipmentLineItem.fillReferenceFields(lineItem); } else { Product product = productService.getByCode(shipmentLineItem.getProductCode()); if (product == null) { throw new DataException("error.unknown.product"); } Long programId = requisitionService.getProgramId(shipmentLineItem.getOrderId()); ProgramProduct programProduct = programProductService.getByProgramAndProductId(programId, product.getId()); if (programProduct != null) { programProduct.setProduct(product); shipmentLineItem.fillReferenceFields(programProduct); } else { shipmentLineItem.fillReferenceFields(product); } } if (shipmentLineItem.getReplacedProductCode() != null) { if (productService.getByCode(shipmentLineItem.getReplacedProductCode()) == null) { throw new DataException("error.unknown.product"); } } shipmentRepository.save(shipmentLineItem); }  void save(ShipmentLineItem shipmentLineItem); void insertShipmentFileInfo(ShipmentFileInfo shipmentFileInfo); List<ShipmentLineItem> getLineItems(long orderId);  }