2323import static org .junit .jupiter .api .Assertions .assertTrue ;
2424import static org .mockito .ArgumentMatchers .any ;
2525import static org .mockito .ArgumentMatchers .eq ;
26+ import static org .mockito .Mockito .doNothing ;
2627import static org .mockito .Mockito .mock ;
2728import static org .mockito .Mockito .when ;
2829
2930import com .google .gson .JsonElement ;
3031import com .google .gson .JsonObject ;
3132import java .math .BigDecimal ;
32- import java .util .Locale ;
33+ import java .time .MonthDay ;
34+ import java .util .HashSet ;
3335import java .util .Set ;
3436import org .apache .fineract .infrastructure .core .api .JsonCommand ;
3537import org .apache .fineract .infrastructure .core .data .ApiParameterError ;
36- import java .time .MonthDay ;
3738import org .apache .fineract .infrastructure .core .exception .PlatformApiDataValidationException ;
38- import org .apache .fineract .infrastructure .core .serialization .FromApiJsonDeserializerHelper ;
39+ import org .apache .fineract .infrastructure .core .serialization .FromJsonHelper ;
3940import org .apache .fineract .portfolio .account .api .StandingInstructionApiConstants ;
4041import org .junit .jupiter .api .BeforeEach ;
4142import org .junit .jupiter .api .Nested ;
4950class StandingInstructionDataValidatorTest {
5051
5152 @ Mock
52- private FromApiJsonDeserializerHelper fromApiJsonHelper ;
53+ private FromJsonHelper fromJsonHelper ;
5354
5455 @ Mock
5556 private AccountTransfersDetailDataValidator accountTransfersDetailDataValidator ;
@@ -63,8 +64,8 @@ class StandingInstructionDataValidatorTest {
6364 @ BeforeEach
6465 void setUp () {
6566 MockitoAnnotations .openMocks (this );
66- when (accountTransfersDetailDataValidator .validate (any (), any ())). thenReturn ( null );
67- when (fromApiJsonHelper .extractMonthDayNamed (any (), any ())).thenReturn (null );
67+ doNothing (). when (accountTransfersDetailDataValidator ) .validate (any (), any ());
68+ when (fromJsonHelper .extractMonthDayNamed (any (), any ())).thenReturn (null );
6869
6970 command = mock (JsonCommand .class );
7071 element = new JsonObject ();
@@ -110,10 +111,10 @@ void fixedInvalidRecurrenceType_shouldFail(int invalidType) {
110111 setupInstructionType (1 );
111112 setupAmount (BigDecimal .valueOf (1000 ));
112113
113- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceTypeParamName , element )).thenReturn (true );
114+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceTypeParamName , element )).thenReturn (true );
114115
115- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceTypeParamName ), eq (element ),
116- any (Locale . class ))).thenReturn (invalidType );
116+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceTypeParamName ), eq (element ),
117+ org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (invalidType );
117118
118119 assertThrows (PlatformApiDataValidationException .class , () -> validator .validateForCreate (command ));
119120 }
@@ -213,7 +214,7 @@ void zeroInterval_shouldFail() {
213214 @ Test
214215 void missingAmountParam_shouldPass () {
215216 setupInstructionType (2 );
216- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .amountParamName , element )).thenReturn (false );
217+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .amountParamName , element )).thenReturn (false );
217218
218219 assertDoesNotThrow (() -> validator .validateForCreate (command ));
219220 }
@@ -232,10 +233,10 @@ class InstructionTypeEdgeCases {
232233
233234 @ Test
234235 void nullType_shouldFail () {
235- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
236+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
236237 .thenReturn (true );
237- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .instructionTypeParamName ),
238- eq (element ), any (Locale . class ))).thenReturn (null );
238+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .instructionTypeParamName ),
239+ eq (element ), org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (null );
239240
240241 assertThrows (PlatformApiDataValidationException .class ,
241242 () -> validator .validateForCreate (command ));
@@ -250,7 +251,7 @@ void invalidTypeValues_shouldFail(int invalidType) {
250251
251252 @ Test
252253 void missingTypeParam_shouldFail () {
253- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
254+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
254255 .thenReturn (false );
255256
256257 PlatformApiDataValidationException ex = assertThrows (
@@ -267,9 +268,9 @@ class PartialDataTests {
267268 void fixedPartialRecurrence_shouldFail () {
268269 setupInstructionType (1 );
269270 setupAmount (BigDecimal .valueOf (1000 ));
270- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element )).thenReturn (true );
271- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceIntervalParamName ), eq (element ),
272- any (Locale . class ))).thenReturn (30 );
271+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element )).thenReturn (true );
272+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceIntervalParamName ), eq (element ),
273+ org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (30 );
273274
274275 PlatformApiDataValidationException ex = assertThrows (PlatformApiDataValidationException .class ,
275276 () -> validator .validateForCreate (command ));
@@ -298,7 +299,7 @@ void fixedOnlyRecurrence_shouldFail() {
298299
299300 @ Test
300301 void emptyJson_shouldFail () {
301- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
302+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
302303 .thenReturn (false );
303304
304305 assertThrows (PlatformApiDataValidationException .class ,
@@ -317,7 +318,7 @@ void fixedMultipleErrors_shouldAccumulate() {
317318
318319 PlatformApiDataValidationException ex = assertThrows (PlatformApiDataValidationException .class ,
319320 () -> validator .validateForCreate (command ));
320- Set <ApiParameterError > errors = ex .getErrors ();
321+ Set <ApiParameterError > errors = new HashSet <>( ex .getErrors () );
321322 assertTrue (errors .size () > 1 );
322323 }
323324
@@ -364,54 +365,54 @@ void duesPartialUpdate_shouldPass() {
364365 }
365366
366367 private void setupInstructionType (int type ) {
367- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
368+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .instructionTypeParamName , element ))
368369 .thenReturn (true );
369- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .instructionTypeParamName ),
370- eq (element ), any (Locale . class ))).thenReturn (type );
370+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .instructionTypeParamName ),
371+ eq (element ), org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (type );
371372 }
372373
373374 private void setupAmount (BigDecimal amount ) {
374- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .amountParamName , element ))
375+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .amountParamName , element ))
375376 .thenReturn (true );
376- when (fromApiJsonHelper .extractBigDecimalWithLocaleNamed (eq (StandingInstructionApiConstants .amountParamName ),
377- eq (element ), any (Locale . class ))).thenReturn (amount );
377+ when (fromJsonHelper .extractBigDecimalWithLocaleNamed (eq (StandingInstructionApiConstants .amountParamName ),
378+ eq (element ), org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (amount );
378379 }
379380
380381 private void setupRecurrence (int recurrenceType , int interval , int frequency , String monthDay ) {
381- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceTypeParamName , element ))
382+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceTypeParamName , element ))
382383 .thenReturn (true );
383- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceTypeParamName ),
384- eq (element ), any (Locale . class ))).thenReturn (recurrenceType );
384+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceTypeParamName ),
385+ eq (element ), org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (recurrenceType );
385386
386- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element ))
387+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element ))
387388 .thenReturn (true );
388- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceIntervalParamName ),
389- eq (element ), any (Locale . class ))).thenReturn (interval );
389+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceIntervalParamName ),
390+ eq (element ), org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (interval );
390391
391- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceFrequencyParamName , element ))
392+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceFrequencyParamName , element ))
392393 .thenReturn (true );
393- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceFrequencyParamName ),
394- eq (element ), any (Locale . class ))).thenReturn (frequency );
394+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceFrequencyParamName ),
395+ eq (element ), org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (frequency );
395396
396- when (fromApiJsonHelper .extractMonthDayNamed (eq (StandingInstructionApiConstants .recurrenceOnMonthDayParamName ),
397+ when (fromJsonHelper .extractMonthDayNamed (eq (StandingInstructionApiConstants .recurrenceOnMonthDayParamName ),
397398 eq (element ))).thenReturn (monthDay != null ? MonthDay .parse ("--" + monthDay ) : null );
398399 }
399400
400401 private void setupRecurrenceInterval (int interval ) {
401- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element ))
402+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element ))
402403 .thenReturn (true );
403- when (fromApiJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceIntervalParamName ),
404- eq (element ), any (Locale . class ))).thenReturn (interval );
404+ when (fromJsonHelper .extractIntegerNamed (eq (StandingInstructionApiConstants .recurrenceIntervalParamName ),
405+ eq (element ), org . mockito . ArgumentMatchers .< Set < String >> any ())).thenReturn (interval );
405406 }
406407
407408 private void setupRecurrenceMissing () {
408- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceTypeParamName , element )).thenReturn (false );
409- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element )).thenReturn (false );
410- when (fromApiJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceFrequencyParamName , element )).thenReturn (false );
409+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceTypeParamName , element )).thenReturn (false );
410+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceIntervalParamName , element )).thenReturn (false );
411+ when (fromJsonHelper .parameterExists (StandingInstructionApiConstants .recurrenceFrequencyParamName , element )).thenReturn (false );
411412 }
412413
413414 private void assertHasError (PlatformApiDataValidationException ex , String paramName ) {
414- boolean found = ex .getErrors ().stream ().anyMatch (e -> e . getParameter (). equals ( paramName ));
415+ boolean found = ex .getErrors ().stream ().anyMatch (e -> paramName . equals ( e . getParameterName () ));
415416 assertTrue (found , "Expected validation error for parameter: " + paramName );
416417 }
417418}
0 commit comments