diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/InternalHoChangeDirectionDueDateLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/InternalHoChangeDirectionDueDateLetterGenerator.java index 585341af3..84993095d 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/InternalHoChangeDirectionDueDateLetterGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/InternalHoChangeDirectionDueDateLetterGenerator.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.DocumentTag; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.Parties; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback; @@ -46,7 +47,7 @@ public boolean canHandle( && Event.CHANGE_DIRECTION_DUE_DATE == event && isInternalCase(asylumCase) && isAppellantInDetention(asylumCase) - && isDirectionPartyRespondent(asylumCase); + && isDirectionPartyValid(asylumCase, Parties.RESPONDENT); } public PreSubmitCallbackResponse handle( diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalChangeDirectionDueDateLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalChangeDirectionDueDateLetterGenerator.java index e90556493..9eaf6b490 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalChangeDirectionDueDateLetterGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalChangeDirectionDueDateLetterGenerator.java @@ -1,9 +1,7 @@ package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter; -import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.DIRECTION_EDIT_PARTIES; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.NOTIFICATION_ATTACHMENT_DOCUMENTS; -import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention; -import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.*; import java.util.Objects; import org.springframework.beans.factory.annotation.Qualifier; @@ -50,7 +48,8 @@ public boolean canHandle( && Event.CHANGE_DIRECTION_DUE_DATE == event && isInternalCase(asylumCase) && isAppellantInDetention(asylumCase) - && isDirectionPartyAppellantOrAppellantRespondent(asylumCase); + && (isDirectionPartyValid(asylumCase, Parties.APPELLANT_AND_RESPONDENT) + || isDirectionPartyValid(asylumCase, Parties.APPELLANT)); } public PreSubmitCallbackResponse handle( @@ -75,10 +74,4 @@ public PreSubmitCallbackResponse handle( return new PreSubmitCallbackResponse<>(asylumCase); } - - private boolean isDirectionPartyAppellantOrAppellantRespondent(AsylumCase asylumCase) { - return asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class) - .map(Parties -> Parties.equals(Parties.APPELLANT) || Parties.equals(Parties.APPELLANT_AND_RESPONDENT)) - .orElse(false); - } } diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtils.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtils.java index 2a31b549e..287634c08 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtils.java @@ -184,9 +184,9 @@ public static Optional> getLatestAddendumEvidenceD return optionalLatestAddendum.isEmpty() ? Optional.empty() : Optional.of(optionalLatestAddendum.get()); } - public static boolean isDirectionPartyRespondent(AsylumCase asylumCase) { + public static boolean isDirectionPartyValid(AsylumCase asylumCase, Parties party) { return asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class) - .map(parties -> parties.equals(Parties.RESPONDENT)) + .map(parties -> parties.equals(party)) .orElse(false); } diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtilsTest.java index 188652e0e..919252fda 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/utils/AsylumCaseUtilsTest.java @@ -19,7 +19,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; @@ -285,14 +284,26 @@ void should_return_empty_list_when_no_addendum_evidence_documents_present() { } @ParameterizedTest - @ValueSource(strings = { "LEGAL_REPRESENTATIVE", "RESPONDENT", "APPELLANT", "BOTH", "APPELLANT_AND_RESPONDENT" }) - void should_return_correct_value_for_is_direction_party_respondent(String party) { - when(asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)).thenReturn(Optional.of(Parties.valueOf(party))); + @EnumSource(value = Parties.class) + void should_return_correct_value_for_is_direction_party_respondent(Parties party) { + when(asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)).thenReturn(Optional.of(Parties.RESPONDENT)); + if (party == Parties.RESPONDENT) { + assertTrue(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party)); + } else { + assertFalse(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party)); + + } + } - if (party.equals("RESPONDENT")) { - assertTrue(AsylumCaseUtils.isDirectionPartyRespondent(asylumCase)); + @ParameterizedTest + @EnumSource(value = Parties.class) + void should_return_correct_value_for_is_direction_party_appellant(Parties party) { + when(asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)).thenReturn(Optional.of(Parties.APPELLANT)); + if (party == Parties.APPELLANT) { + assertTrue(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party)); } else { - assertFalse(AsylumCaseUtils.isDirectionPartyRespondent(asylumCase)); + assertFalse(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party)); + } }