diff --git a/src/main/java/uk/gov/hmcts/probate/transformer/CaseDataTransformer.java b/src/main/java/uk/gov/hmcts/probate/transformer/CaseDataTransformer.java index de70f468d8..1a0c68f6f2 100644 --- a/src/main/java/uk/gov/hmcts/probate/transformer/CaseDataTransformer.java +++ b/src/main/java/uk/gov/hmcts/probate/transformer/CaseDataTransformer.java @@ -56,7 +56,12 @@ public void transformForSolicitorApplicationCompletion(CallbackRequest callbackR public void transformCaseDataForValidateProbate(CallbackRequest callbackRequest) { - final var caseData = callbackRequest.getCaseDetails().getData(); + final var caseDetails = callbackRequest.getCaseDetails(); + final var caseData = caseDetails.getData(); + + solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType( + caseDetails); + resetCaseDataTransformer.resetExecutorLists(caseData); solicitorApplicationCompletionTransformer.setFieldsIfSolicitorIsNotNamedInWillAsAnExecutor(caseData); solicitorApplicationCompletionTransformer.mapSolicitorExecutorFieldsOnAppDetailsComplete(caseData); diff --git a/src/main/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformer.java b/src/main/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformer.java index 1603d39860..1d798545e1 100644 --- a/src/main/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformer.java +++ b/src/main/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformer.java @@ -14,7 +14,9 @@ import java.util.List; import static uk.gov.hmcts.probate.model.ApplicationState.CASE_PRINTED; +import static uk.gov.hmcts.probate.model.Constants.CASE_TYPE_GRANT_OF_PROBATE; import static uk.gov.hmcts.probate.model.Constants.NO; +import static uk.gov.hmcts.probate.model.Constants.TITLE_AND_CLEARING_NONE_OF_THESE; @Component @Slf4j @@ -69,4 +71,30 @@ public void setFieldsOnServiceRequest(CaseDetails caseDetails, BigDecimal totalA caseDetails.setState(CASE_PRINTED.getId()); } } + + public void clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(CaseDetails caseDetails) { + if (featureToggleService.enableDuplicateExecutorFiltering()) { + final var caseId = caseDetails.getId(); + final var caseData = caseDetails.getData(); + + final var titleAndClearingType = caseData.getTitleAndClearingType(); + final var caseType = caseData.getCaseType(); + + final var primaryApplicantApplying = caseData.isPrimaryApplicantApplying(); + final var isNotNoneOfTheseTCT = titleAndClearingType != null + && !TITLE_AND_CLEARING_NONE_OF_THESE.equalsIgnoreCase(titleAndClearingType); + final var isGrantOfProbate = CASE_TYPE_GRANT_OF_PROBATE.equalsIgnoreCase(caseType); + + if (isNotNoneOfTheseTCT + && primaryApplicantApplying + && isGrantOfProbate) { + log.info("In GrantOfProbate case {} we have primary applicant applying for non-NoneOfThese " + + "TitleAndClearingType {}, clear PrimaryApplicant fields", + caseId, + titleAndClearingType); + + caseData.clearPrimaryApplicant(); + } + } + } } diff --git a/src/test/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformerTest.java b/src/test/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformerTest.java index 0d0f54a42d..9b605f728b 100644 --- a/src/test/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformerTest.java +++ b/src/test/java/uk/gov/hmcts/probate/transformer/solicitorexecutors/SolicitorApplicationCompletionTransformerTest.java @@ -32,8 +32,12 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static uk.gov.hmcts.probate.model.Constants.CASE_TYPE_GRANT_OF_PROBATE; +import static uk.gov.hmcts.probate.model.Constants.TITLE_AND_CLEARING_NONE_OF_THESE; import static uk.gov.hmcts.probate.model.Constants.TITLE_AND_CLEARING_TRUST_CORP; import static uk.gov.hmcts.probate.util.CommonVariables.ADDITIONAL_EXECUTOR_APPLYING; import static uk.gov.hmcts.probate.util.CommonVariables.ADDITIONAL_EXECUTOR_NOT_APPLYING; @@ -260,4 +264,121 @@ void shouldSetPaymentTakenNotApplicableWhenNoServiceRequest() { assertEquals(NOT_APPLICABLE, caseData.getPaymentTaken()); } + + // given Case + // and CaseType is GrantOfProbate + // and TitleClearingType is not NoneOfThese + // and PrimaryApplicantApplying is true + // when transformer clearPrimaryForNoneOfThese called + // then primaryApplicantClear is called + @Test + void givenCaseWithoutNoneOfTheseTitleClearingTypeANDPrimaryApplicant_whenChecked_thenPrimaryApplicantDataCleared() { + final CaseData caseData = mock(CaseData.class); + final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L); + + when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true); + + when(caseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE); + when(caseData.getTitleAndClearingType()).thenReturn(""); + when(caseData.isPrimaryApplicantApplying()).thenReturn(true); + + solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType( + caseDetails); + + verify(caseData, times(1)).clearPrimaryApplicant(); + } + + // given Case + // and CaseType is NOT GrantOfProbate + // and TitleClearingType is not NoneOfThese + // and PrimaryApplicantApplying is true + // when transformer clearPrimaryForNoneOfThese called + // then primaryApplicantClear is NOT called + @Test + void givenCaseNotGOPWoutNoneOfTheseTCTypeANDPrimaryApplicant_whenChecked_thenPrimaryApplicantDataNOTCleared() { + final CaseData caseData = mock(CaseData.class); + final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L); + + when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true); + + when(caseData.getCaseType()).thenReturn(""); + when(caseData.getTitleAndClearingType()).thenReturn(""); + when(caseData.isPrimaryApplicantApplying()).thenReturn(true); + + solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType( + caseDetails); + + verify(caseData, times(0)).clearPrimaryApplicant(); + } + + // given Case + // and CaseType is GrantOfProbate + // and TitleClearingType is NoneOfThese + // and PrimaryApplicantApplying is true + // when transformer clearPrimaryForNoneOfThese called + // then primaryApplicantClear is not called + @Test + void givenCaseWithNoneOfTheseTitleClearingTypeANDPrimaryApplicant_whenChecked_thenPrimaryApplicantDataNOTCleared() { + final CaseData caseData = mock(CaseData.class); + final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L); + + when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true); + + when(caseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE); + when(caseData.getTitleAndClearingType()).thenReturn(TITLE_AND_CLEARING_NONE_OF_THESE); + when(caseData.isPrimaryApplicantApplying()).thenReturn(true); + + solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType( + caseDetails); + + verify(caseData, times(0)).clearPrimaryApplicant(); + } + + // given Case + // and CaseType is GrantOfProbate + // and TitleClearingType is not NoneOfThese + // and PrimaryApplicantApplying is false + // when transformer clearPrimaryForNoneOfThese called + // then primaryApplicantClear is not called + @Test + void givenCaseWoutNoneOfTheseTitleClearingTypeANDWoutPrmryApplicant_whenChecked_thenPrmryApplicantDataNOTCleared() { + final CaseData realCaseData = CaseData.builder().build(); + final CaseData spyCaseData = spy(realCaseData); + final CaseDetails caseDetails = new CaseDetails(spyCaseData, null, 0L); + + when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true); + + when(spyCaseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE); + when(spyCaseData.getTitleAndClearingType()).thenReturn(""); + when(spyCaseData.isPrimaryApplicantApplying()).thenReturn(false); + + solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType( + caseDetails); + + verify(spyCaseData, times(0)).clearPrimaryApplicant(); + } + + // given Case + // and CaseType is GrantOfProbate + // and TitleClearingType is not NoneOfThese + // and PrimaryApplicantApplying is true + // and enableDuplicateApplicant is false + // when transformer clearPrimaryForNoneOfThese called + // then primaryApplicantClear is called + @Test + void givenCaseWithoutNoneOfTheseTtlClrngTypeANDPrmryApplANDDuplDisabled_whenChecked_thenPrmryApplDataNOTCleared() { + final CaseData caseData = mock(CaseData.class); + final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L); + + when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(false); + + when(caseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE); + when(caseData.getTitleAndClearingType()).thenReturn(""); + when(caseData.isPrimaryApplicantApplying()).thenReturn(true); + + solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType( + caseDetails); + + verify(caseData, times(0)).clearPrimaryApplicant(); + } }