@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); }
@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); }
@Test public void testAddNewOrder() { orderServiceImpl.addNewOrder(); verify(orderDAOMock, times(1)).create(any(Order.class)); }
// If method return "null" @Test public void testFindOrderByIdWhenReturnNull() { when(orderDAOMock.findById(1)).thenReturn(null); OrderDTO result = orderServiceImpl.findOrderById(1); assertNull(result); }