CoffeeShop { @Scheduled(every = "2s") public void processUnfinishedOrders() { entityManager.createNamedQuery(Order.FIND_UNFINISHED, Order.class) .getResultList() .forEach(orderProcessor::processOrder); }  Set<CoffeeType> getCoffeeTypes(); Set<Origin> getOrigins(final CoffeeType type); Origin getOrigin(String name); void createOrder(Order order); Order getOrder(UUID id); List<Order> getOrders(); @Scheduled(every = "2s") void processUnfinishedOrders(); void updateOrder(UUID id, Order order);  }
@Test @SuppressWarnings("unchecked") void testProcessUnfinishedOrders() { List<Order> desiredOrders = TestData.unfinishedOrders(); TypedQuery mockQuery = mock(TypedQuery.class); when(testObject.entityManager.createNamedQuery(Order.FIND_UNFINISHED, Order.class)).thenReturn(mockQuery); when(mockQuery.getResultList()).thenReturn(desiredOrders); ArgumentCaptor<Order> orderCaptor = ArgumentCaptor.forClass(Order.class); testObject.processUnfinishedOrders(); verify(testObject.entityManager).createNamedQuery(Order.FIND_UNFINISHED, Order.class); verify(testObject.orderProcessor, times(desiredOrders.size())).processOrder(orderCaptor.capture()); assertThat(orderCaptor.getAllValues()).containsExactlyElementsOf(desiredOrders); orderCaptor.getAllValues().forEach(o -> assertThat(o).isPreparing()); }