### Question:
OrderServiceImpl implements OrderService { @Override @Transactional public Order postOrder(Order order) { OrderEvent orderEvent = new OrderEvent(); orderEvent.setOccurredOn(Instant.now()); orderEvent.setOrderEventType(OrderEventType.PURCHASED); order.getOrderEvents().add(orderEvent); order = orderDAO.saveOrUpdate(order); order.setTrackingNumber(trackingNumberGenerationStrategy.generatetrackingNumber(order)); return order; }  @Override @Transactional(readOnly = true) Collection<Crust> getCrusts(); @Override @Transactional(readOnly = true) Collection<PizzaSize> getPizzaSizes(); @Override @Transactional(readOnly = true) Collection<BakeStyle> getBakeStyles(); @Override @Transactional(readOnly = true) Collection<CutStyle> getCutStyles(); @Override @Transactional(readOnly = true) Collection<Ingredient> getIngredients(); @Override Collection<Integer> getQuantities(); @Override void addOrderItemToCart(PizzaOrderDTO pizzaOrderDTO); @Override void removeOrderItem(int orderItemIndex); @Override void emptyCart(); @Override void replaceOrderItem(int orderItemIndex, PizzaOrderDTO pizzaOrderDTO); @Override PizzaOrderDTO getPizzaOrderDTOByOrderItemId(int orderItemIndex); @Override @Transactional(readOnly = true) IngredientType getIngredientTypeByIngredientId(Long ingredientId); @Override @Transactional(readOnly = true) Ingredient getIngredientById(Long ingredientId); @Override @Transactional Order postOrder(Order order); @Override @Transactional(readOnly = true) Order getOrderByTrackingNumber(String trackingNumber); @Override @Transactional void addReviewToOrderByTrackingNumber(String trackingNumber, ReviewDTO reviewDTO); @Override @Transactional(readOnly = true) Optional<PizzaOrderDTO> getPizzaOrderDTOByOrderItemId(Long orderItemId); int getMaxQuantity(); void setMaxQuantity(int maxQuantity); int getMinQuantity(); void setMinQuantity(int minQuantity); CrustDAO getCrustDAO(); @Autowired void setCrustDAO(CrustDAO crustDAO); PizzaSizeDAO getPizzaSizeDAO(); @Autowired void setPizzaSizeDAO(PizzaSizeDAO pizzaSizeDAO); BakeStyleDAO getBakeStyleDAO(); @Autowired void setBakeStyleDAO(BakeStyleDAO bakeStyleDAO); CutStyleDAO getCutStyleDAO(); @Autowired void setCutStyleDAO(CutStyleDAO cutStyleDAO); IngredientDAO getIngredientDAO(); @Autowired void setIngredientDAO(IngredientDAO ingredientDAO); OrderDAO getOrderDAO(); @Autowired void setOrderDAO(OrderDAO orderDAO); Cart getCart(); @Autowired void setCart(Cart cart); CustomerDAO getCustomerDAO(); @Autowired void setCustomerDAO(CustomerDAO customerDAO); TrackingNumberGenerationStrategy getTrackingNumberGenerationStrategy(); @Autowired void setTrackingNumberGenerationStrategy(TrackingNumberGenerationStrategy trackingNumberGenerationStrategy); OrderItemDAO getOrderItemDAO(); @Autowired void setOrderItemDAO(OrderItemDAO orderItemDAO);  }### Answer:
@Test public void shouldPostOrder() throws Exception { Order order = new Order(); String trackingNumber = "42"; Long orderId = 42L; when(trackingNumberGenerationStrategy.generatetrackingNumber(order)).thenReturn(trackingNumber); when(orderDAO.saveOrUpdate(order)).thenAnswer(invocation -> { order.setId(orderId); return order; }); Order result = orderService.postOrder(order); assertThat(result.getId()).isEqualTo(orderId); assertThat(result.getTrackingNumber()).isEqualTo(trackingNumber); Condition<OrderEvent> purchaseEvent = new Condition<>(orderEvent -> orderEvent.getOrderEventType() == OrderEventType.PURCHASED, "purchase event"); assertThat(result.getOrderEvents()).first().is(purchaseEvent); }