@Test public void shouldThrowErrorIfPODAlreadyConfirmed() throws Exception { OrderPOD orderPod = new OrderPOD(3L); orderPod.setOrderNumber("ON123"); OrderPOD spyOrderPod = spy(orderPod); doNothing().when(spyOrderPod).validate(); when(orderService.getByOrderNumber("ON123")).thenReturn(new Order(4L)); when(podService.getPODByOrderId(4L)).thenReturn(new OrderPOD()); expectedException.expect(DataException.class); expectedException.expectMessage("error.restapi.delivery.already.confirmed"); restPODService.updatePOD(spyOrderPod, 1L); }
@Transactional public void updatePOD(OrderPOD orderPod, Long userId) { orderPod.setCreatedBy(userId); orderPod.setModifiedBy(userId); Order order = orderService.getByOrderNumber(orderPod.getOrderNumber()); if(order == null ) throw new DataException("error.restapi.invalid.order"); orderPod.setOrderId(order.getId()); orderPod.validate(); validateOrderForPOD(orderPod); podService.checkPermissions(orderPod); insertPOD(orderPod); }
RestPODService { @Transactional public void updatePOD(OrderPOD orderPod, Long userId) { orderPod.setCreatedBy(userId); orderPod.setModifiedBy(userId); Order order = orderService.getByOrderNumber(orderPod.getOrderNumber()); if(order == null ) throw new DataException("error.restapi.invalid.order"); orderPod.setOrderId(order.getId()); orderPod.validate(); validateOrderForPOD(orderPod); podService.checkPermissions(orderPod); insertPOD(orderPod); } }
RestPODService { @Transactional public void updatePOD(OrderPOD orderPod, Long userId) { orderPod.setCreatedBy(userId); orderPod.setModifiedBy(userId); Order order = orderService.getByOrderNumber(orderPod.getOrderNumber()); if(order == null ) throw new DataException("error.restapi.invalid.order"); orderPod.setOrderId(order.getId()); orderPod.validate(); validateOrderForPOD(orderPod); podService.checkPermissions(orderPod); insertPOD(orderPod); }  }
RestPODService { @Transactional public void updatePOD(OrderPOD orderPod, Long userId) { orderPod.setCreatedBy(userId); orderPod.setModifiedBy(userId); Order order = orderService.getByOrderNumber(orderPod.getOrderNumber()); if(order == null ) throw new DataException("error.restapi.invalid.order"); orderPod.setOrderId(order.getId()); orderPod.validate(); validateOrderForPOD(orderPod); podService.checkPermissions(orderPod); insertPOD(orderPod); }  @Transactional void updatePOD(OrderPOD orderPod, Long userId); }
RestPODService { @Transactional public void updatePOD(OrderPOD orderPod, Long userId) { orderPod.setCreatedBy(userId); orderPod.setModifiedBy(userId); Order order = orderService.getByOrderNumber(orderPod.getOrderNumber()); if(order == null ) throw new DataException("error.restapi.invalid.order"); orderPod.setOrderId(order.getId()); orderPod.validate(); validateOrderForPOD(orderPod); podService.checkPermissions(orderPod); insertPOD(orderPod); }  @Transactional void updatePOD(OrderPOD orderPod, Long userId);  }