|
| 1 | +package uk.gov.hmcts.reform.iacaseapi.domain.handlers.postsubmit; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 8 | +import static org.mockito.Mockito.reset; |
| 9 | +import static org.mockito.Mockito.when; |
| 10 | + |
| 11 | +import org.junit.jupiter.api.BeforeEach; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 14 | +import org.mockito.Mock; |
| 15 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 16 | +import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase; |
| 17 | +import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event; |
| 18 | +import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback; |
| 19 | +import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse; |
| 20 | + |
| 21 | +@ExtendWith(MockitoExtension.class) |
| 22 | +@SuppressWarnings("unchecked") |
| 23 | +class ForceFtpaDecidedStateConfirmationTest { |
| 24 | + |
| 25 | + @Mock |
| 26 | + private Callback<AsylumCase> callback; |
| 27 | + |
| 28 | + private ForceFtpaDecidedStateConfirmation forceFtpaDecidedStateConfirmation; |
| 29 | + |
| 30 | + @BeforeEach |
| 31 | + public void setUp() { |
| 32 | + forceFtpaDecidedStateConfirmation = new ForceFtpaDecidedStateConfirmation(); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void should_return_confirmation() { |
| 37 | + |
| 38 | + when(callback.getEvent()).thenReturn(Event.FORCE_FTPA_DECIDED_STATE); |
| 39 | + |
| 40 | + PostSubmitCallbackResponse callbackResponse = |
| 41 | + forceFtpaDecidedStateConfirmation.handle(callback); |
| 42 | + |
| 43 | + assertNotNull(callbackResponse); |
| 44 | + assertTrue(callbackResponse.getConfirmationHeader().isPresent()); |
| 45 | + assertTrue(callbackResponse.getConfirmationBody().isPresent()); |
| 46 | + |
| 47 | + assertThat( |
| 48 | + callbackResponse.getConfirmationHeader().get()) |
| 49 | + .contains("# The appeal has been moved to the FTPA decided state"); |
| 50 | + |
| 51 | + assertThat( |
| 52 | + callbackResponse.getConfirmationBody().get()) |
| 53 | + .contains("#### What happens next"); |
| 54 | + |
| 55 | + assertThat( |
| 56 | + callbackResponse.getConfirmationBody().get()) |
| 57 | + .contains("The appeal can now be progressed from the FTPA decided state."); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void handling_should_throw_if_cannot_actually_handle() { |
| 62 | + |
| 63 | + assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.handle(callback)) |
| 64 | + .hasMessage("Cannot handle callback") |
| 65 | + .isExactlyInstanceOf(IllegalStateException.class); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + void it_can_handle_callback() { |
| 70 | + |
| 71 | + for (Event event : Event.values()) { |
| 72 | + |
| 73 | + when(callback.getEvent()).thenReturn(event); |
| 74 | + |
| 75 | + boolean canHandle = forceFtpaDecidedStateConfirmation.canHandle(callback); |
| 76 | + |
| 77 | + if (event == Event.FORCE_FTPA_DECIDED_STATE) { |
| 78 | + |
| 79 | + assertTrue(canHandle); |
| 80 | + } else { |
| 81 | + assertFalse(canHandle); |
| 82 | + } |
| 83 | + |
| 84 | + reset(callback); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + void should_not_allow_null_arguments() { |
| 90 | + |
| 91 | + assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.canHandle(null)) |
| 92 | + .hasMessage("callback must not be null") |
| 93 | + .isExactlyInstanceOf(NullPointerException.class); |
| 94 | + |
| 95 | + assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.handle(null)) |
| 96 | + .hasMessage("callback must not be null") |
| 97 | + .isExactlyInstanceOf(NullPointerException.class); |
| 98 | + } |
| 99 | +} |
0 commit comments