Skip to content

Commit

Permalink
P4ADEV-1774 fix sonar constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoGiuliani committed Jan 10, 2025
1 parent fabd8ad commit d76e547
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.gov.pagopa.pu.debtpositions.mapper.TransferMapper;
import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
import it.gov.pagopa.pu.debtpositions.model.PaymentOption;
import it.gov.pagopa.pu.debtpositions.util.Repositories;
import it.gov.pagopa.pu.debtpositions.model.Transfer;
import it.gov.pagopa.pu.debtpositions.repository.*;
import jakarta.transaction.Transactional;
Expand All @@ -23,11 +24,12 @@ public class DebtPositionServiceImpl implements DebtPositionService {
private final InstallmentMapper installmentMapper;
private final TransferMapper transferMapper;

public DebtPositionServiceImpl(DebtPositionRepository debtPositionRepository, PaymentOptionRepository paymentOptionRepository, InstallmentPIIRepository installmentRepository, TransferRepository transferRepository, DebtPositionMapper debtPositionMapper, PaymentOptionMapper paymentOptionMapper, InstallmentMapper installmentMapper, TransferMapper transferMapper) {
this.debtPositionRepository = debtPositionRepository;
this.paymentOptionRepository = paymentOptionRepository;
this.installmentRepository = installmentRepository;
this.transferRepository = transferRepository;
public DebtPositionServiceImpl(Repositories repositories, DebtPositionMapper debtPositionMapper, PaymentOptionMapper paymentOptionMapper,
InstallmentMapper installmentMapper, TransferMapper transferMapper) {
this.debtPositionRepository = repositories.debtPositionRepository();
this.paymentOptionRepository = repositories.paymentOptionRepository();
this.installmentRepository = repositories.installmentRepository();
this.transferRepository = repositories.transferRepository();
this.debtPositionMapper = debtPositionMapper;
this.paymentOptionMapper = paymentOptionMapper;
this.installmentMapper = installmentMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.gov.pagopa.pu.debtpositions.util;

import it.gov.pagopa.pu.debtpositions.repository.DebtPositionRepository;
import it.gov.pagopa.pu.debtpositions.repository.InstallmentPIIRepository;
import it.gov.pagopa.pu.debtpositions.repository.PaymentOptionRepository;
import it.gov.pagopa.pu.debtpositions.repository.TransferRepository;

public record Repositories(DebtPositionRepository debtPositionRepository,
PaymentOptionRepository paymentOptionRepository,
InstallmentPIIRepository installmentRepository,
TransferRepository transferRepository) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import it.gov.pagopa.pu.debtpositions.mapper.TransferMapper;
import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
import it.gov.pagopa.pu.debtpositions.model.PaymentOption;
import it.gov.pagopa.pu.debtpositions.util.Repositories;
import it.gov.pagopa.pu.debtpositions.model.Transfer;
import it.gov.pagopa.pu.debtpositions.repository.DebtPositionRepository;
import it.gov.pagopa.pu.debtpositions.repository.InstallmentPIIRepository;
import it.gov.pagopa.pu.debtpositions.repository.PaymentOptionRepository;
import it.gov.pagopa.pu.debtpositions.repository.TransferRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down Expand Up @@ -54,9 +55,20 @@ class DebtPositionServiceImplTest {
@Mock
private TransferMapper transferMapper;

@InjectMocks
private DebtPositionServiceImpl debtPositionService;

@BeforeEach
void setUp() {
Repositories repositories = new Repositories(debtPositionRepository, paymentOptionRepository, installmentRepository, transferRepository);
debtPositionService = new DebtPositionServiceImpl(
repositories,
debtPositionMapper,
paymentOptionMapper,
installmentMapper,
transferMapper
);
}

@Test
void givenValidDebtPositionDTO_WhenSaveDebtPosition_ThenSaveAllEntities() {
DebtPositionDTO inputDto = new DebtPositionDTO();
Expand Down Expand Up @@ -103,7 +115,6 @@ void givenValidDebtPositionDTO_WhenSaveDebtPosition_ThenSaveAllEntities() {
Mockito.verify(transferMapper).mapToModel(transferDTO);
}


@Test
void givenRepositoryFails_WhenSaveDebtPosition_ThenThrowRuntimeException() {
DebtPositionDTO inputDto = new DebtPositionDTO();
Expand Down

0 comments on commit d76e547

Please sign in to comment.