Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [P4PU-763] added null check on mapper #167

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

@Component
public class BizEventsUserDetail2UserDetailDTOMapper {

public UserDetailDTO mapUserDetail(BizEventsUserDetailDTO bizEventsUserDetailDTO){
if (bizEventsUserDetailDTO == null) {
return null;
}

return UserDetailDTO.builder()
.name(bizEventsUserDetailDTO.getName())
.taxCode(bizEventsUserDetailDTO.getTaxCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
public class BizEventsWalletInfo2WalletInfoDTOMapper {

public WalletInfoDTO mapWalletInfo(BizEventsWalletInfoDTO bizEventsWalletInfoDTO){
if(bizEventsWalletInfoDTO == null){
return null;
}

return WalletInfoDTO.builder()
.accountHolder(bizEventsWalletInfoDTO.getAccountHolder())
.brand(bizEventsWalletInfoDTO.getBrand())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import it.gov.pagopa.arc.fakers.bizEvents.BizEventsCartItemDTOFaker;
import it.gov.pagopa.arc.model.generated.CartItemDTO;
import it.gov.pagopa.arc.model.generated.UserDetailDTO;
import it.gov.pagopa.arc.utils.TestUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mapstruct.factory.Mappers;
Expand All @@ -14,8 +15,7 @@
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -58,6 +58,39 @@ void givenBizEventsCartItemDTOWhenMapCartThenReturnCartItemDTO() {
assertEquals(debtorResponse, result.getDebtor());
assertEquals("960000000094659945", result.getRefNumberValue());
assertEquals("IUV", result.getRefNumberType());
TestUtils.assertNotNullFields(result);
Mockito.verify(userDetailsMapperMock, Mockito.times(2)).mapUserDetail(any());
}

@Test
void givenBizEventsCartItemDTOWhenUserDetailDTONullThenReturnCartItemDTO() {
//given
BizEventsUserDetailDTO payee = CommonUserDetailDTOFaker.mockBizEventsUserDetailDTO(CommonUserDetailDTOFaker.USER_DETAIL_PAYEE);

BizEventsUserDetailDTO debtor = CommonUserDetailDTOFaker.mockBizEventsUserDetailDTO(CommonUserDetailDTOFaker.USER_DETAIL_DEBTOR);

UserDetailDTO payeeResponse = null;

UserDetailDTO debtorResponse = UserDetailDTO.builder()
.taxCode("TAX_CODE")
.build();

Mockito.when(userDetailsMapperMock.mapUserDetail(payee)).thenReturn(payeeResponse);
Mockito.when(userDetailsMapperMock.mapUserDetail(debtor)).thenReturn(debtorResponse);

BizEventsCartItemDTO cartItemDTO = BizEventsCartItemDTOFaker.mockInstance(payee,debtor);
//when
CartItemDTO result = cartItemMapper.mapCart(cartItemDTO);
//then
assertNotNull(result);
assertEquals("pagamento", result.getSubject());
assertEquals(545230L, result.getAmount());
assertNull(result.getPayee());
assertNull(result.getDebtor().getName());
assertEquals(debtorResponse.getTaxCode(), result.getDebtor().getTaxCode());
assertEquals("960000000094659945", result.getRefNumberValue());
assertEquals("IUV", result.getRefNumberType());
Mockito.verify(userDetailsMapperMock, Mockito.times(2)).mapUserDetail(any());
TestUtils.assertNotNullFields(result, "payee");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import it.gov.pagopa.arc.connector.bizevents.dto.BizEventsUserDetailDTO;
import it.gov.pagopa.arc.fakers.CommonUserDetailDTOFaker;
import it.gov.pagopa.arc.model.generated.UserDetailDTO;
import it.gov.pagopa.arc.utils.TestUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

class BizEventsUserDetail2UserDetailDTOMapperTest {

Expand All @@ -28,6 +28,14 @@ void givenBizEventsUserDetailDTOWhenMapUserDetailThenReturnUserDetailDTO() {
assertNotNull(result);
assertEquals("CREDITOR_NAME", result.getName());
assertEquals("CREDITOR_TAX_CODE", result.getTaxCode());
TestUtils.assertNotNullFields(result);
}

@Test
void givenNullBizEventsUserDetailDTOWhenMapUserDetailThenReturnNullUserDetailDTO() {
//when
UserDetailDTO result = userDetailMapper.mapUserDetail(null);
//then
assertNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import it.gov.pagopa.arc.connector.bizevents.dto.BizEventsWalletInfoDTO;
import it.gov.pagopa.arc.fakers.CommonWalletInfoDTOFaker;
import it.gov.pagopa.arc.model.generated.WalletInfoDTO;
import it.gov.pagopa.arc.utils.TestUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

class BizEventsWalletInfo2WalletInfoDTOMapperTest {
private BizEventsWalletInfo2WalletInfoDTOMapper walletInfoMapper;
Expand All @@ -29,5 +29,14 @@ void givenBizEventsWalletInfoDTOWhenMapWalletInfoThenReturnWalletInfoDTO() {
assertEquals("VISA", result.getBrand());
assertEquals("0932", result.getBlurredNumber());
assertEquals("user@paypal.com", result.getMaskedEmail());
TestUtils.assertNotNullFields(result);
}

@Test
void givenNullBizEventsWalletInfoDTOWhenMapWalletInfoThenReturnNullWalletInfoDTO() {
//when
WalletInfoDTO result = walletInfoMapper.mapWalletInfo(null);
//then
assertNull(result);
}
}
Loading