PetMapper { public Pet map(PetDTO dto) { var pet = new Pet(); pet.setPetId(dto.getPetId()); pet.setName(dto.getName()); pet.setPetType(dto.getPetType()); pet.setStatus(PetStatus.valueOf(dto.getStatus().name())); return pet; }  Pet map(PetDTO dto); PetDTO map(Pet pet);  }
@Test void map_fromDTO() { var petDTO = new PetDTO(); petDTO.setPetId(PET_ID); petDTO.setName(PET_NAME); petDTO.setPetType(PET_TYPE); petDTO.setStatus(PetStatusDTO.AVAILABLE); var pet = PET_MAPPER.map(petDTO); Assertions.assertAll(() -> { Assertions.assertNotNull(pet); Assertions.assertEquals(petDTO.getPetId(), pet.getPetId()); Assertions.assertEquals(petDTO.getName(), pet.getName()); Assertions.assertEquals(petDTO.getPetType(), pet.getPetType()); Assertions.assertEquals(petDTO.getStatus().name(), pet.getStatus().name()); }); }
@Test void map_fromObject() { var pet = new Pet(); pet.setPetId(PET_ID); pet.setName(PET_NAME); pet.setPetType(PET_TYPE); pet.setStatus(PetStatus.AVAILABLE); var petDTO = PET_MAPPER.map(pet); Assertions.assertAll(() -> { Assertions.assertNotNull(petDTO); Assertions.assertEquals(pet.getPetId(), petDTO.getPetId()); Assertions.assertEquals(pet.getName(), petDTO.getName()); Assertions.assertEquals(pet.getPetType(), petDTO.getPetType()); Assertions.assertEquals(pet.getStatus().name(), petDTO.getStatus().name()); }); }