### Question:
AccountReferenceAccessValidator { public ValidationResult validate(AisConsent aisConsent, List<AccountReference> references, String accountId, AisConsentRequestType consentRequestType) { if (AisConsentRequestType.GLOBAL == consentRequestType) { return ValidationResult.valid(); } if (isConsentForAllAvailableAccounts(aisConsent) || !isValidAccountByAccess(accountId, references)) { return ValidationResult.invalid(ErrorType.AIS_401, CONSENT_INVALID); } return ValidationResult.valid(); }  ValidationResult validate(AisConsent aisConsent, List<AccountReference> references, String accountId, AisConsentRequestType consentRequestType);  }### Answer:
@Test void validate_success() { ValidationResult validationResult = validator.validate(aisConsent, Collections.singletonList(accountReference), ACCOUNT_ID, AisConsentRequestType.DEDICATED_ACCOUNTS); assertTrue(validationResult.isValid()); }
@Test void validate_success_global() { ValidationResult validationResult = validator.validate(aisConsent, Collections.singletonList(accountReference), ACCOUNT_ID, AisConsentRequestType.GLOBAL); assertTrue(validationResult.isValid()); }
@Test void validate_notValidByAccountId() { ValidationResult validationResult = validator.validate(aisConsent, Collections.singletonList(accountReference), WRONG_ACCOUNT_ID, AisConsentRequestType.DEDICATED_ACCOUNTS); assertFalse(validationResult.isValid()); assertEquals(ErrorType.AIS_401, validationResult.getMessageError().getErrorType()); assertEquals(CONSENT_INVALID, validationResult.getMessageError().getTppMessage().getMessageErrorCode()); }
@Test void validate_notValidAvailableAccount() { aisConsent = jsonReader.getObjectFromFile("json/service/validator/ais/account/xs2a-account-consent-all-available-accounts.json", AisConsent.class); ValidationResult validationResult = validator.validate(aisConsent, Collections.emptyList(), ACCOUNT_ID, AisConsentRequestType.DEDICATED_ACCOUNTS); assertFalse(validationResult.isValid()); assertEquals(ErrorType.AIS_401, validationResult.getMessageError().getErrorType()); assertEquals(CONSENT_INVALID, validationResult.getMessageError().getTppMessage().getMessageErrorCode()); }
@Test void validate_notValidAvailableAccountWithValances() { aisConsent = jsonReader.getObjectFromFile("json/service/validator/ais/account/xs2a-account-consent-all-available-accounts-with-balance.json", AisConsent.class); ValidationResult validationResult = validator.validate(aisConsent, Collections.emptyList(), ACCOUNT_ID, AisConsentRequestType.DEDICATED_ACCOUNTS); assertFalse(validationResult.isValid()); assertEquals(ErrorType.AIS_401, validationResult.getMessageError().getErrorType()); assertEquals(CONSENT_INVALID, validationResult.getMessageError().getTppMessage().getMessageErrorCode()); }
@Test void validate_AccountReferenceWithoutResourceId() { AccountReference accountReference = jsonReader.getObjectFromFile("json/service/validator/ais/account/xs2a-account-reference-without-resource-id.json", AccountReference.class); ValidationResult validationResult = validator.validate(aisConsent, Collections.singletonList(accountReference), ACCOUNT_ID, AisConsentRequestType.DEDICATED_ACCOUNTS); assertTrue(validationResult.isNotValid()); assertEquals(ErrorType.AIS_401, validationResult.getMessageError().getErrorType()); assertEquals(CONSENT_INVALID, validationResult.getMessageError().getTppMessage().getMessageErrorCode()); }