Skip to content

Commit

Permalink
fix(ccls-2061): updates following review
Browse files Browse the repository at this point in the history
  • Loading branch information
porritta committed Feb 21, 2024
1 parent 0d825a7 commit a69542c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,40 @@ public void testCreateApplication(String fileInput, String auditTrailMethod, Lis
// null/ignore the ids as theses are generated by the database
nullModelIds(savedApplicationDetails);

updateExpectedBooleans(applicationDetail);

assertEquals(applicationDetail, savedApplicationDetails);
}

private void updateExpectedBooleans(ApplicationDetail applicationDetail) {
applicationDetail.setAmendment(
applicationDetail.getAmendment() == null
? Boolean.FALSE : applicationDetail.getAmendment());
applicationDetail.setAppMode(
applicationDetail.getAppMode() == null
? Boolean.FALSE : applicationDetail.getAppMode());
applicationDetail.setAward(
applicationDetail.getAward() == null
? Boolean.FALSE : applicationDetail.getAward());
applicationDetail.setEditProceedingsAndCostsAllowed(
applicationDetail.getEditProceedingsAndCostsAllowed() == null
? Boolean.FALSE : applicationDetail.getEditProceedingsAndCostsAllowed());
applicationDetail.setLarScopeFlag(applicationDetail.getLarScopeFlag() == null
? Boolean.FALSE : applicationDetail.getLarScopeFlag());
applicationDetail.setLeadProceedingChanged(applicationDetail.getLeadProceedingChanged() == null
? Boolean.FALSE : applicationDetail.getLeadProceedingChanged());
applicationDetail.setMeansAssessmentAmended(applicationDetail.getMeansAssessmentAmended() == null
? Boolean.FALSE : applicationDetail.getMeansAssessmentAmended());
applicationDetail.setMeritsAssessmentAmended(applicationDetail.getMeritsAssessmentAmended() == null
? Boolean.FALSE : applicationDetail.getMeritsAssessmentAmended());
applicationDetail.setMeritsReassessmentRequired(
applicationDetail.getMeritsReassessmentRequired() == null
? Boolean.FALSE : applicationDetail.getMeritsReassessmentRequired());
applicationDetail.setOpponentAppliedForFunding(
applicationDetail.getOpponentAppliedForFunding() == null
? Boolean.FALSE : applicationDetail.getOpponentAppliedForFunding());
}

private void nullModelIds(ApplicationDetail applicationDetail) {
if (applicationDetail.getLinkedCases() != null) {
for (LinkedCase linkedCase : applicationDetail.getLinkedCases()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.laa.ccms.data.api.service;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -331,7 +332,7 @@ public void testGetApplication() {
assertEquals("AAP", result.getCategoryOfLaw().getId());
assertEquals("Claim Against Public Authority", result.getCategoryOfLaw().getDisplayValue());
assertNull(result.getRelationToLinkedCase());
assertNull(result.getOpponentAppliedForFunding());
assertFalse(result.getOpponentAppliedForFunding());
assertEquals("Unsubmitted", result.getStatus().getDisplayValue());
assertEquals("UNSUBMITTED", result.getStatus().getId());
assertEquals("Phil", result.getClient().getFirstName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
* and the service or API layers, ensuring consistent object translation.
*/

@Mapper(componentModel = "spring", config = IgnoreUnmappedMapperConfig.class)
@Mapper(componentModel = "spring",
config = IgnoreUnmappedMapperConfig.class,
uses = CommonMapper.class)
public interface ApplicationMapper {

@Mapping(target = "id", ignore = true)
Expand Down Expand Up @@ -374,12 +376,4 @@ void updateScopeLimitation(

ApplicationDetails toApplicationDetails(Page<Application> application);

/**
* Global mapper to default Booleans to FALSE in the case of a null source value.
* @param flag - the source value
* @return the source value, or FALSE.
*/
default Boolean toBoolean(Boolean flag) {
return flag != null ? flag : Boolean.FALSE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.laa.ccms.caab.api.mapper;

import org.mapstruct.Mapper;

/**
* Common mappings which can be used by other mappers.
*/
@Mapper(componentModel = "spring")
public interface CommonMapper {

/**
* Global mapper to default Booleans to FALSE in the case of a null source value.
*
* @param flag - the source value
* @return the source value, or FALSE.
*/
default Boolean toBoolean(Boolean flag) {
return flag != null ? flag : Boolean.FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import uk.gov.laa.ccms.caab.api.entity.Address;
Expand Down Expand Up @@ -44,8 +49,12 @@
import uk.gov.laa.ccms.caab.model.IntDisplayValue;
import uk.gov.laa.ccms.caab.model.StringDisplayValue;

@ExtendWith(MockitoExtension.class)
public class ApplicationMapperTest {
@Mock(answer = Answers.CALLS_REAL_METHODS)
private CommonMapper commonMapper;

@InjectMocks
private final ApplicationMapper mapper = new ApplicationMapperImpl();

private Date createdAt;
Expand Down

0 comments on commit a69542c

Please sign in to comment.