Skip to content

Commit

Permalink
P4PU-287 added test for PullPaymentServiceImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe-LaManna committed Jul 29, 2024
1 parent 8eb2860 commit b635652
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package it.gov.pagopa.arc.service.pullpayment;

import it.gov.pagopa.arc.connector.pullpayment.PullPaymentConnector;
import it.gov.pagopa.arc.connector.pullpayment.dto.PullPaymentInstallmentDTO;
import it.gov.pagopa.arc.connector.pullpayment.dto.PullPaymentNoticeDTO;
import it.gov.pagopa.arc.connector.pullpayment.dto.PullPaymentOptionDTO;
import it.gov.pagopa.arc.dto.mapper.pullpayment.PaymentNoticesListDTOMapper;
import it.gov.pagopa.arc.dto.mapper.pullpayment.PullPaymentNoticeDTO2PaymentNoticeDTO;
import it.gov.pagopa.arc.fakers.connector.pullPayment.PullPaymentInstallmentDTOFaker;
import it.gov.pagopa.arc.fakers.connector.pullPayment.PullPaymentNoticeDTOFaker;
import it.gov.pagopa.arc.fakers.connector.pullPayment.PullPaymentOptionDTOFaker;
import it.gov.pagopa.arc.fakers.paymentNotices.PaymentNoticeDTOFaker;
import it.gov.pagopa.arc.model.generated.PaymentNoticeDTO;
import it.gov.pagopa.arc.model.generated.PaymentNoticesListDTO;
Expand Down Expand Up @@ -125,6 +129,49 @@ void givenParametersWhenRetrievePaymentNoticesListFromPullPaymentWithMultiplePay

}

@Test
void givenParametersWhenRetrievePaymentNoticesListFromPullPaymentWithMultipleNumberOfInstallmentsThenReturnFilteredPaymentNoticesListDTO() {
//given
PullPaymentNoticeDTO pullPaymentNoticeDTO1 = PullPaymentNoticeDTOFaker.mockInstance(true);
PullPaymentNoticeDTO pullPaymentNoticeDTO2 = PullPaymentNoticeDTOFaker.mockInstance(true);

PullPaymentInstallmentDTO pullPaymentInstallmentDTO = PullPaymentInstallmentDTOFaker.mockInstance();
PullPaymentOptionDTO pullPaymentOptionDTO = PullPaymentOptionDTOFaker.mockInstance(pullPaymentInstallmentDTO, true);
pullPaymentNoticeDTO1.setPaymentOptions(List.of(pullPaymentOptionDTO));

List<PullPaymentNoticeDTO> pullPaymentNoticeDTOList = List.of(pullPaymentNoticeDTO1, pullPaymentNoticeDTO2);

Mockito.when(pullPaymentConnectorMock.getPaymentNotices(DUMMY_FISCAL_CODE,DUE_DATE,SIZE,PAGE)).thenReturn(pullPaymentNoticeDTOList);

PaymentNoticeDTO paymentNoticeDTO1 = PaymentNoticeDTOFaker.mockInstance(true);


List<PaymentNoticeDTO> paymentNoticesList = List.of(paymentNoticeDTO1);

PaymentNoticesListDTO paymentNoticesListExpected = PaymentNoticesListDTO
.builder()
.paymentNotices(
paymentNoticesList)
.build();

Mockito.when(paymentNoticeDTOMapperMock.toPaymentNoticeDTO(pullPaymentNoticeDTO2)).thenReturn(paymentNoticeDTO1);

Mockito.when(paymentNoticesListDTOMapperMock.toPaymentNoticesListDTO(paymentNoticesList)).thenReturn(paymentNoticesListExpected);
//when
PaymentNoticesListDTO result = pullPaymentService.retrievePaymentNoticesListFromPullPayment(DUE_DATE, SIZE, PAGE);
//then
Assertions.assertNotNull(result);
Assertions.assertEquals(1, result.getPaymentNotices().size());
Assertions.assertEquals(paymentNoticesList, result.getPaymentNotices());

assertThat(result.getPaymentNotices()).allMatch(paymentNotice -> paymentNotice.getPaymentOptions().stream().allMatch(paymentOption -> paymentOption.getNumberOfInstallments() == 1));

Mockito.verify(pullPaymentConnectorMock).getPaymentNotices(anyString(),any(),anyInt(),anyInt());
Mockito.verify(paymentNoticeDTOMapperMock).toPaymentNoticeDTO(any());
Mockito.verify(paymentNoticesListDTOMapperMock).toPaymentNoticesListDTO(anyList());

}

@Test
void givenParametersWhenRetrieveEmptyPaymentNoticesListFromPullPaymentThenReturnEmptyList() {
//given
Expand Down

0 comments on commit b635652

Please sign in to comment.