@Test void shouldThrowPetNotAvailable_whenPetIsNotAvailable() { var pet = new Pet(); pet.setStatus(PetStatus.SOLD); BDDMockito.given(petRepository.findById(PET_ID)).willReturn(Optional.of(pet)); Assertions.assertThrows(PetNotAvailableException.class, () -> petOrderer.order(PET_ID)); }
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);  }