From 0b517f155ff0ab958976913dd117e0dd419c77d1 Mon Sep 17 00:00:00 2001 From: Vitolo-Andrea Date: Mon, 11 Nov 2024 10:40:50 +0100 Subject: [PATCH] Clean code --- .../tpp/controller/TppControllerTest.java | 8 ++----- .../pagopa/tpp/service/TppServiceTest.java | 14 ++++-------- .../it/gov/pagopa/tpp/utils/TestUtils.java | 22 +++++++++++++++++++ .../tpp/{ => utils}/faker/TppDTOFaker.java | 2 +- .../tpp/{ => utils}/faker/TppFaker.java | 2 +- 5 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 src/test/java/it/gov/pagopa/tpp/utils/TestUtils.java rename src/test/java/it/gov/pagopa/tpp/{ => utils}/faker/TppDTOFaker.java (94%) rename src/test/java/it/gov/pagopa/tpp/{ => utils}/faker/TppFaker.java (94%) diff --git a/src/test/java/it/gov/pagopa/tpp/controller/TppControllerTest.java b/src/test/java/it/gov/pagopa/tpp/controller/TppControllerTest.java index aa1ff49..bc3edf0 100644 --- a/src/test/java/it/gov/pagopa/tpp/controller/TppControllerTest.java +++ b/src/test/java/it/gov/pagopa/tpp/controller/TppControllerTest.java @@ -2,8 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.gov.pagopa.tpp.dto.TppDTO; -import it.gov.pagopa.tpp.dto.TppIdList; -import it.gov.pagopa.tpp.faker.TppDTOFaker; import it.gov.pagopa.tpp.service.TppServiceImpl; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -17,6 +15,8 @@ import java.util.List; +import static it.gov.pagopa.tpp.utils.TestUtils.*; + @WebFluxTest(TppControllerImpl.class) class TppControllerTest { @@ -29,10 +29,6 @@ class TppControllerTest { @Autowired private ObjectMapper objectMapper; - private static final TppDTO MOCK_TPP_DTO = TppDTOFaker.mockInstance(true); - - private static final List MOCK_TPP_DTO_LIST = List.of(MOCK_TPP_DTO); - private static final TppIdList MOCK_TPP_ID_LIST = new TppIdList(List.of(MOCK_TPP_DTO.getTppId())); @Test void upsert_Ok() { diff --git a/src/test/java/it/gov/pagopa/tpp/service/TppServiceTest.java b/src/test/java/it/gov/pagopa/tpp/service/TppServiceTest.java index fa39124..a4edeab 100644 --- a/src/test/java/it/gov/pagopa/tpp/service/TppServiceTest.java +++ b/src/test/java/it/gov/pagopa/tpp/service/TppServiceTest.java @@ -4,10 +4,7 @@ import it.gov.pagopa.tpp.dto.TppDTO; import it.gov.pagopa.tpp.dto.mapper.TppObjectToDTOMapper; import it.gov.pagopa.tpp.configuration.ExceptionMap; -import it.gov.pagopa.tpp.faker.TppDTOFaker; -import it.gov.pagopa.tpp.faker.TppFaker; import org.junit.jupiter.api.function.Executable; -import it.gov.pagopa.tpp.model.Tpp; import it.gov.pagopa.tpp.model.mapper.TppDTOToObjectMapper; import it.gov.pagopa.tpp.repository.TppRepository; import org.junit.jupiter.api.Test; @@ -22,6 +19,7 @@ import java.util.List; +import static it.gov.pagopa.tpp.utils.TestUtils.*; import static org.junit.jupiter.api.Assertions.*; @ExtendWith(SpringExtension.class) @@ -42,18 +40,14 @@ class TppServiceTest { @Autowired private TppDTOToObjectMapper mapperToObject; - private static final TppDTO MOCK_TPP_DTO = TppDTOFaker.mockInstance(true); - private static final Tpp MOCK_TPP = TppFaker.mockInstance(true); - private static final List MOCK_TPP_DTO_LIST = List.of(MOCK_TPP_DTO); - private static final List MOCK_TPP_LIST = List.of(MOCK_TPP); - private static final List MOCK_TPP_ID_LIST = List.of(MOCK_TPP_DTO.getTppId()); + @Test void getEnabled_Ok() { - Mockito.when(tppRepository.findByTppIdInAndStateTrue(MOCK_TPP_ID_LIST)) + Mockito.when(tppRepository.findByTppIdInAndStateTrue(MOCK_TPP_ID_STRING_LIST)) .thenReturn(Flux.fromIterable(MOCK_TPP_LIST)); - List response = tppService.getEnabledList(MOCK_TPP_ID_LIST).block(); + List response = tppService.getEnabledList(MOCK_TPP_ID_STRING_LIST).block(); assertNotNull(response); assertEquals(MOCK_TPP_DTO_LIST, response); diff --git a/src/test/java/it/gov/pagopa/tpp/utils/TestUtils.java b/src/test/java/it/gov/pagopa/tpp/utils/TestUtils.java new file mode 100644 index 0000000..1ee9af7 --- /dev/null +++ b/src/test/java/it/gov/pagopa/tpp/utils/TestUtils.java @@ -0,0 +1,22 @@ +package it.gov.pagopa.tpp.utils; + +import it.gov.pagopa.tpp.dto.TppDTO; +import it.gov.pagopa.tpp.dto.TppIdList; +import it.gov.pagopa.tpp.utils.faker.TppDTOFaker; +import it.gov.pagopa.tpp.utils.faker.TppFaker; +import it.gov.pagopa.tpp.model.Tpp; + +import java.util.List; + +public class TestUtils { + + public TestUtils (){} + + public static final TppDTO MOCK_TPP_DTO = TppDTOFaker.mockInstance(true); + public static final Tpp MOCK_TPP = TppFaker.mockInstance(true); + public static final List MOCK_TPP_DTO_LIST = List.of(MOCK_TPP_DTO); + public static final List MOCK_TPP_LIST = List.of(MOCK_TPP); + public static final List MOCK_TPP_ID_STRING_LIST = List.of(MOCK_TPP_DTO.getTppId()); + public static final TppIdList MOCK_TPP_ID_LIST = new TppIdList(MOCK_TPP_ID_STRING_LIST); + +} diff --git a/src/test/java/it/gov/pagopa/tpp/faker/TppDTOFaker.java b/src/test/java/it/gov/pagopa/tpp/utils/faker/TppDTOFaker.java similarity index 94% rename from src/test/java/it/gov/pagopa/tpp/faker/TppDTOFaker.java rename to src/test/java/it/gov/pagopa/tpp/utils/faker/TppDTOFaker.java index 74ea1e3..e992537 100644 --- a/src/test/java/it/gov/pagopa/tpp/faker/TppDTOFaker.java +++ b/src/test/java/it/gov/pagopa/tpp/utils/faker/TppDTOFaker.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.tpp.faker; +package it.gov.pagopa.tpp.utils.faker; import it.gov.pagopa.tpp.dto.TppDTO; import it.gov.pagopa.tpp.enums.AuthenticationType; diff --git a/src/test/java/it/gov/pagopa/tpp/faker/TppFaker.java b/src/test/java/it/gov/pagopa/tpp/utils/faker/TppFaker.java similarity index 94% rename from src/test/java/it/gov/pagopa/tpp/faker/TppFaker.java rename to src/test/java/it/gov/pagopa/tpp/utils/faker/TppFaker.java index 084f539..c767326 100644 --- a/src/test/java/it/gov/pagopa/tpp/faker/TppFaker.java +++ b/src/test/java/it/gov/pagopa/tpp/utils/faker/TppFaker.java @@ -1,4 +1,4 @@ -package it.gov.pagopa.tpp.faker; +package it.gov.pagopa.tpp.utils.faker; import it.gov.pagopa.tpp.enums.AuthenticationType; import it.gov.pagopa.tpp.model.Contact;