@Test public void testSetReadyStatusForOrderWhenEverythingOk() throws LogiwebValidationException { Order testOrder = createValidTestOrder(); when(orderDAOMock.findById(testOrder.getOrderId())).thenReturn(testOrder); orderServiceImpl.setReadyStatusForOrder(testOrder.getOrderId()); verify(orderDAOMock, times(1)).update(testOrder); }
private Order createValidTestOrder() { Truck truck = new Truck(); truck.setDriverCount(1); truck.setDriversInTruck(new HashSet<>(Arrays.asList(new Driver()))); Order order = new Order(); order.setOrderLines(new HashSet<>(Arrays.asList(new Freight()))); order.setOrderStatus(OrderStatus.CREATED); order.setAssignedTruckFK(truck); return order; }
@Test(expected = LogiwebValidationException.class) public void testAssignTruckToOrderWhenTruckIsNotOk() throws LogiwebValidationException { Truck testTruck = new Truck(); testTruck.setTruckId(1); testTruck.setTruckStatus(TruckStatus.FAULTY); Order testOrder = new Order(); testOrder.setOrderLines(new HashSet<>(Arrays.asList(new Freight()))); testTruck.setOrderForThisTruck(testOrder); when(truckDAOMock.findById(1)).thenReturn(testTruck); when(orderDAOMock.findById(1)).thenReturn(testOrder); orderServiceImpl.assignTruck(1, 1); }