PetRegister { public Pet register(Pet pet) { var petToSave = new Pet(); petToSave.setPetId(idGenerator.generate()); petToSave.setName(pet.getName()); petToSave.setPetType(pet.getPetType()); petToSave.setStatus(pet.getStatus()); return petRepository.save(petToSave); } PetRegister(IdGenerator idGenerator, PetRepository petRepository); Pet register(Pet pet);  }
@Test void register() { BDDMockito.given(petRepository.save(Mockito.any(Pet.class))) .willAnswer(invocation -> invocation.getArgument(0)); var pet = new Pet(); pet.setPetType(PET_TYPE); pet.setName(PET_NAME); pet.setStatus(PetStatus.AVAILABLE); var petRegistered = petRegister.register(pet); Assertions.assertNotNull(petRegistered); Assertions.assertEquals(PET_ID, petRegistered.getPetId()); Assertions.assertEquals(pet.getPetType(), petRegistered.getPetType()); Assertions.assertEquals(pet.getName(), petRegistered.getName()); Assertions.assertEquals(pet.getStatus(), petRegistered.getStatus()); BDDMockito.then(petRepository).should().save(Mockito.any(Pet.class)); }