Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitolo-Andrea committed Nov 11, 2024
1 parent 07ef71f commit 0b517f1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +15,8 @@

import java.util.List;

import static it.gov.pagopa.tpp.utils.TestUtils.*;

@WebFluxTest(TppControllerImpl.class)
class TppControllerTest {

Expand All @@ -29,10 +29,6 @@ class TppControllerTest {
@Autowired
private ObjectMapper objectMapper;

private static final TppDTO MOCK_TPP_DTO = TppDTOFaker.mockInstance(true);

private static final List<TppDTO> 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() {
Expand Down
14 changes: 4 additions & 10 deletions src/test/java/it/gov/pagopa/tpp/service/TppServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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<TppDTO> MOCK_TPP_DTO_LIST = List.of(MOCK_TPP_DTO);
private static final List<Tpp> MOCK_TPP_LIST = List.of(MOCK_TPP);
private static final List<String> 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<TppDTO> response = tppService.getEnabledList(MOCK_TPP_ID_LIST).block();
List<TppDTO> response = tppService.getEnabledList(MOCK_TPP_ID_STRING_LIST).block();

assertNotNull(response);
assertEquals(MOCK_TPP_DTO_LIST, response);
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/it/gov/pagopa/tpp/utils/TestUtils.java
Original file line number Diff line number Diff line change
@@ -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<TppDTO> MOCK_TPP_DTO_LIST = List.of(MOCK_TPP_DTO);
public static final List<Tpp> MOCK_TPP_LIST = List.of(MOCK_TPP);
public static final List<String> 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);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 0b517f1

Please sign in to comment.