diff --git a/src/test/java/com/capgemini/training/appointmentbooking/logic/impl/FindTreatmentUcImplTest.java b/src/test/java/com/capgemini/training/appointmentbooking/logic/impl/FindTreatmentUcImplTest.java new file mode 100644 index 0000000..b3692e6 --- /dev/null +++ b/src/test/java/com/capgemini/training/appointmentbooking/logic/impl/FindTreatmentUcImplTest.java @@ -0,0 +1,76 @@ +package com.capgemini.training.appointmentbooking.logic.impl; + +import com.capgemini.training.appointmentbooking.common.BaseTest; +import com.capgemini.training.appointmentbooking.common.to.TreatmentCto; +import com.capgemini.training.appointmentbooking.dataaccess.entity.TreatmentEntity; +import com.capgemini.training.appointmentbooking.dataaccess.repository.TreatmentRepository; +import com.capgemini.training.appointmentbooking.logic.mapper.TreatmentCtoMapper; +import com.capgemini.training.appointmentbooking.logic.mapper.TreatmentMapper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mapstruct.factory.Mappers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; + +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class FindTreatmentUcImplTest extends BaseTest { + + @Mock + private TreatmentRepository treatmentRepository; + + @InjectMocks + private FindTreatmentUcImpl findTreatmentUc; + + @Spy + private static TreatmentMapper treatmentMapper = Mappers.getMapper(TreatmentMapper.class); + + @Spy + private static TreatmentCtoMapper treatmentCtoMapper = Mappers.getMapper(TreatmentCtoMapper.class); + + @Test + void shouldFindTreatmentById() { + // given + Long treatmentId = -1L; + TreatmentEntity treatmentEntity = new TreatmentEntity(); + treatmentEntity.setId(treatmentId); + treatmentEntity.setName("Dummy Name"); + treatmentEntity.setDescription("Dummy Description"); + + when(treatmentRepository.findById(treatmentId)).thenReturn(Optional.of(treatmentEntity)); + + // when + Optional treatmentCto = findTreatmentUc.findById(treatmentId); + + // then + assertThat(treatmentCto).isPresent(); + treatmentCto.ifPresent(a -> { + assertThat(a.treatmentEto().id()).isEqualTo(treatmentEntity.getId()); + assertThat(a.treatmentEto().name()).isEqualTo(treatmentEntity.getName()); + assertThat(a.treatmentEto().description()).isEqualTo(treatmentEntity.getDescription()); + }); + } + + @Test + void shouldFindAllTreatments() { + // given + String name = "Dummy Name"; + TreatmentEntity treatmentEntity = new TreatmentEntity(); + treatmentEntity.setName(name); + when(treatmentRepository.findAll()).thenReturn(List.of(treatmentEntity, treatmentEntity, treatmentEntity)); + + // when + List result = findTreatmentUc.findAll(); + + // then + assertThat(result).hasSize(3); + assertThat(result).allMatch(appointment -> name.equals(appointment.treatmentEto().name())); + } + +} \ No newline at end of file