22
33import static org .assertj .core .api .Assertions .assertThatThrownBy ;
44import static org .junit .jupiter .api .Assertions .*;
5+ import static org .mockito .Mockito .never ;
56import static org .mockito .Mockito .times ;
67import static org .mockito .Mockito .verify ;
78import static org .mockito .Mockito .when ;
@@ -47,6 +48,7 @@ void setUp() {
4748 void should_remove_appellant_address_and_contact_info () {
4849 when (asylumCase .read (AsylumCaseFieldDefinition .APPELLANT_IN_DETENTION , YesOrNo .class ))
4950 .thenReturn (Optional .of (YES ));
51+ when (asylumCase .read (DETENTION_FACILITY , String .class )).thenReturn (Optional .of ("prison" ));
5052 PreSubmitCallbackResponse <AsylumCase > response = detainedEditAppealHandler .handle (PreSubmitCallbackStage .ABOUT_TO_SUBMIT , callback );
5153 assertNotNull (response );
5254 verify (asylumCase , times (1 ))
@@ -133,6 +135,7 @@ void handling_should_throw_if_argument_null() {
133135 void should_remove_ada_suitability_fields_when_editing_to_detained_non_ada () {
134136 when (asylumCase .read (AsylumCaseFieldDefinition .APPELLANT_IN_DETENTION , YesOrNo .class )).thenReturn (Optional .of (YES ));
135137 when (asylumCase .read (IS_ACCELERATED_DETAINED_APPEAL , YesOrNo .class )).thenReturn (Optional .of (YesOrNo .NO ));
138+ when (asylumCase .read (DETENTION_FACILITY , String .class )).thenReturn (Optional .of ("prison" ));
136139 PreSubmitCallbackResponse <AsylumCase > response = detainedEditAppealHandler .handle (PreSubmitCallbackStage .ABOUT_TO_SUBMIT , callback );
137140
138141 assertNotNull (response );
@@ -149,6 +152,7 @@ void should_remove_ada_suitability_appellant_attendance_fields_when_editing_hear
149152 when (asylumCase .read (AsylumCaseFieldDefinition .APPELLANT_IN_DETENTION , YesOrNo .class )).thenReturn (Optional .of (YES ));
150153 when (asylumCase .read (IS_ACCELERATED_DETAINED_APPEAL , YesOrNo .class )).thenReturn (Optional .of (YES ));
151154 when (asylumCase .read (SUITABILITY_HEARING_TYPE_YES_OR_NO , YesOrNo .class )).thenReturn (Optional .of (yesOrNo ));
155+ when (asylumCase .read (DETENTION_FACILITY , String .class )).thenReturn (Optional .of ("prison" ));
152156 PreSubmitCallbackResponse <AsylumCase > response = detainedEditAppealHandler .handle (PreSubmitCallbackStage .ABOUT_TO_SUBMIT , callback );
153157
154158 assertNotNull (response );
@@ -168,6 +172,7 @@ void should_remove_ada_suitability_interpreter_services_fields_when_attendance_a
168172 when (asylumCase .read (SUITABILITY_HEARING_TYPE_YES_OR_NO , YesOrNo .class )).thenReturn (Optional .of (YES ));
169173 when (asylumCase .read (SUITABILITY_APPELLANT_ATTENDANCE_YES_OR_NO_1 , YesOrNo .class )).thenReturn (Optional .of (NO ));
170174 when (asylumCase .read (SUITABILITY_APPELLANT_ATTENDANCE_YES_OR_NO_2 , YesOrNo .class )).thenReturn (Optional .of (NO ));
175+ when (asylumCase .read (DETENTION_FACILITY , String .class )).thenReturn (Optional .of ("prison" ));
171176 PreSubmitCallbackResponse <AsylumCase > response = detainedEditAppealHandler .handle (PreSubmitCallbackStage .ABOUT_TO_SUBMIT , callback );
172177
173178 assertNotNull (response );
@@ -176,4 +181,36 @@ void should_remove_ada_suitability_interpreter_services_fields_when_attendance_a
176181 verify (asylumCase , times (1 )).clear (AsylumCaseFieldDefinition .SUITABILITY_INTERPRETER_SERVICES_YES_OR_NO );
177182 verify (asylumCase , times (1 )).clear (AsylumCaseFieldDefinition .SUITABILITY_INTERPRETER_SERVICES_LANGUAGE );
178183 }
184+
185+ @ Test
186+ void should_not_clear_appellant_address_when_detention_facility_is_other () {
187+ when (asylumCase .read (AsylumCaseFieldDefinition .APPELLANT_IN_DETENTION , YesOrNo .class ))
188+ .thenReturn (Optional .of (YES ));
189+ when (asylumCase .read (DETENTION_FACILITY , String .class )).thenReturn (Optional .of ("other" ));
190+ PreSubmitCallbackResponse <AsylumCase > response = detainedEditAppealHandler .handle (PreSubmitCallbackStage .ABOUT_TO_SUBMIT , callback );
191+
192+ assertNotNull (response );
193+ verify (asylumCase , times (1 ))
194+ .clear (AsylumCaseFieldDefinition .APPELLANT_HAS_FIXED_ADDRESS );
195+ verify (asylumCase , never ()).clear (AsylumCaseFieldDefinition .APPELLANT_ADDRESS );
196+ verify (asylumCase , times (1 )).clear (AsylumCaseFieldDefinition .SEARCH_POSTCODE );
197+ verify (asylumCase , times (1 ))
198+ .clear (AsylumCaseFieldDefinition .HAS_CORRESPONDENCE_ADDRESS );
199+ verify (asylumCase , times (1 ))
200+ .clear (AsylumCaseFieldDefinition .APPELLANT_OUT_OF_COUNTRY_ADDRESS );
201+ verify (asylumCase , times (1 )).clear (AsylumCaseFieldDefinition .CONTACT_PREFERENCE );
202+ verify (asylumCase , times (1 )).clear (AsylumCaseFieldDefinition .EMAIL );
203+ verify (asylumCase , times (1 )).clear (AsylumCaseFieldDefinition .MOBILE_NUMBER );
204+ }
205+
206+ @ Test
207+ void should_throw_exception_when_detention_facility_missing_for_detained_appellant () {
208+ when (asylumCase .read (AsylumCaseFieldDefinition .APPELLANT_IN_DETENTION , YesOrNo .class ))
209+ .thenReturn (Optional .of (YES ));
210+ when (asylumCase .read (DETENTION_FACILITY , String .class )).thenReturn (Optional .empty ());
211+
212+ assertThatThrownBy (() -> detainedEditAppealHandler .handle (PreSubmitCallbackStage .ABOUT_TO_SUBMIT , callback ))
213+ .hasMessage ("detentionFacility missing for appellant in detention" )
214+ .isExactlyInstanceOf (IllegalStateException .class );
215+ }
179216}
0 commit comments