@Test void shouldIncludeRandomOrderIdWhenNoParentOrderExists() { try (MockedStatic<UUID> mockedUuid = Mockito.mockStatic(UUID.class)) { mockedUuid.when(UUID::randomUUID).thenReturn(defaultUuid); Order result = cut.createOrder("MacBook Pro", 2L, null); assertEquals("8d8b30e3-de52-4f1c-a71c-9905a8043dac", result.getId()); } }
public Order createOrder(String productName, Long amount, String parentOrderId) { Order order = new Order(); order.setId(parentOrderId == null ? UUID.randomUUID().toString() : parentOrderId); order.setCreationDate(LocalDateTime.now()); order.setAmount(amount); order.setProductName(productName); return order; }
OrderService { public Order createOrder(String productName, Long amount, String parentOrderId) { Order order = new Order(); order.setId(parentOrderId == null ? UUID.randomUUID().toString() : parentOrderId); order.setCreationDate(LocalDateTime.now()); order.setAmount(amount); order.setProductName(productName); return order; } }
OrderService { public Order createOrder(String productName, Long amount, String parentOrderId) { Order order = new Order(); order.setId(parentOrderId == null ? UUID.randomUUID().toString() : parentOrderId); order.setCreationDate(LocalDateTime.now()); order.setAmount(amount); order.setProductName(productName); return order; }  }
OrderService { public Order createOrder(String productName, Long amount, String parentOrderId) { Order order = new Order(); order.setId(parentOrderId == null ? UUID.randomUUID().toString() : parentOrderId); order.setCreationDate(LocalDateTime.now()); order.setAmount(amount); order.setProductName(productName); return order; }  Order createOrder(String productName, Long amount, String parentOrderId); }
OrderService { public Order createOrder(String productName, Long amount, String parentOrderId) { Order order = new Order(); order.setId(parentOrderId == null ? UUID.randomUUID().toString() : parentOrderId); order.setCreationDate(LocalDateTime.now()); order.setAmount(amount); order.setProductName(productName); return order; }  Order createOrder(String productName, Long amount, String parentOrderId);  }