@Test void shouldReturnAndOrder_whenPetIsFound_andPetStatusIsAdequate() { BDDMockito.given(idGenerator.generate()).willReturn(ID); var pet = new Pet(); pet.setStatus(PetStatus.AVAILABLE); BDDMockito.given(petRepository.findById(PET_ID)).willReturn(Optional.of(pet)); BDDMockito.given(orderRepository.save(Mockito.any(Order.class))) .willAnswer(invocation -> invocation.getArgument(0)); var order = petOrderer.order(PET_ID); Assertions.assertNotNull(order); Assertions.assertEquals(ID, order.getOrderId()); Assertions.assertEquals(OrderStatus.PLACED, order.getStatus()); }
public Order order(String petId) { var pet = petRepository.findById(petId).orElseThrow(() -> new PetNotFoundException(petId)); if (PetStatus.AVAILABLE != pet.getStatus()) { throw new PetNotAvailableException(petId); } var order = new Order(); order.setOrderId(idGenerator.generate()); order.setPet(pet); order.setStatus(OrderStatus.PLACED); return orderRepository.save(order); }
PetOrderer { public Order order(String petId) { var pet = petRepository.findById(petId).orElseThrow(() -> new PetNotFoundException(petId)); if (PetStatus.AVAILABLE != pet.getStatus()) { throw new PetNotAvailableException(petId); } var order = new Order(); order.setOrderId(idGenerator.generate()); order.setPet(pet); order.setStatus(OrderStatus.PLACED); return orderRepository.save(order); } }
PetOrderer { public Order order(String petId) { var pet = petRepository.findById(petId).orElseThrow(() -> new PetNotFoundException(petId)); if (PetStatus.AVAILABLE != pet.getStatus()) { throw new PetNotAvailableException(petId); } var order = new Order(); order.setOrderId(idGenerator.generate()); order.setPet(pet); order.setStatus(OrderStatus.PLACED); return orderRepository.save(order); } PetOrderer(
			IdGenerator idGenerator,
			PetRepository petRepository,
			OrderRepository orderRepository
	); }
PetOrderer { public Order order(String petId) { var pet = petRepository.findById(petId).orElseThrow(() -> new PetNotFoundException(petId)); if (PetStatus.AVAILABLE != pet.getStatus()) { throw new PetNotAvailableException(petId); } var order = new Order(); order.setOrderId(idGenerator.generate()); order.setPet(pet); order.setStatus(OrderStatus.PLACED); return orderRepository.save(order); } PetOrderer(
			IdGenerator idGenerator,
			PetRepository petRepository,
			OrderRepository orderRepository
	); Order order(String petId); }
PetOrderer { public Order order(String petId) { var pet = petRepository.findById(petId).orElseThrow(() -> new PetNotFoundException(petId)); if (PetStatus.AVAILABLE != pet.getStatus()) { throw new PetNotAvailableException(petId); } var order = new Order(); order.setOrderId(idGenerator.generate()); order.setPet(pet); order.setStatus(OrderStatus.PLACED); return orderRepository.save(order); } PetOrderer(
			IdGenerator idGenerator,
			PetRepository petRepository,
			OrderRepository orderRepository
	); Order order(String petId);  }