### Question:
AccountAccessValidator { public ValidationResult validate(AisConsent aisConsent, boolean withBalance) { if (withBalance) { AisConsentData aisConsentData = aisConsent.getConsentData(); if (aisConsentData.getAllPsd2() != null) { return ValidationResult.valid(); } if (EnumSet.of(AccountAccessType.ALL_ACCOUNTS, AccountAccessType.ALL_ACCOUNTS_WITH_OWNER_NAME) .contains(aisConsentData.getAvailableAccountsWithBalance())) { return ValidationResult.valid(); } if (CollectionUtils.isEmpty(aisConsent.getAccess().getBalances())) { return ValidationResult.invalid(ErrorType.AIS_401, CONSENT_INVALID); } } return ValidationResult.valid(); }  ValidationResult validate(AisConsent aisConsent, boolean withBalance);  }### Answer:
@Test void testValidate_allAccountConsentWithBalances_shouldReturnValid(){ aisConsent = jsonReader.getObjectFromFile( "json/service/validator/ais/account/xs2a-account-consent-all-available-accounts-with-balance.json", AisConsent.class); ValidationResult actual = accountAccessValidator.validate(aisConsent, true); assertTrue(actual.isValid()); }
@Test void testValidate_allAccountConsentWithBalances_withOwnerName_shouldReturnValid(){ aisConsent = jsonReader.getObjectFromFile( "json/service/validator/ais/account/xs2a-account-consent-all-available-accounts-with-balance_with_owner_name.json", AisConsent.class); ValidationResult actual = accountAccessValidator.validate(aisConsent, true); assertTrue(actual.isValid()); }
@Test void testValidate_withoutBalance_shouldReturnValid() { aisConsent = jsonReader.getObjectFromFile("json/service/validator/ais/account/xs2a-account-consent.json", AisConsent.class); ValidationResult actual = accountAccessValidator.validate(aisConsent, false); assertTrue(actual.isValid()); }
@Test void testValidate_withBalanceAndNullBalances_shouldReturnError() { aisConsent = jsonReader.getObjectFromFile("json/service/validator/ais/account/xs2a-account-consent.json", AisConsent.class); aisConsent.getAccess().getBalances().clear(); ValidationResult actual = accountAccessValidator.validate(aisConsent, true); assertTrue(actual.isNotValid()); assertEquals(AIS_VALIDATION_ERROR, actual.getMessageError()); }
@Test void testValidate_globalConsent_withBalanceAndNullBalances_shouldReturnError() { aisConsent = jsonReader.getObjectFromFile("json/service/validator/ais/account/xs2a-account-consent-global.json", AisConsent.class); assertNull(aisConsent.getAccess().getBalances()); ValidationResult actual = accountAccessValidator.validate(aisConsent, true); assertTrue(actual.isValid()); }
@Test void testValidate_globalConsent_withoutBalanceAndNullBalances_shouldReturnError() { aisConsent = jsonReader.getObjectFromFile("json/service/validator/ais/account/xs2a-account-consent-global.json", AisConsent.class); assertNull(aisConsent.getAccess().getBalances()); ValidationResult actual = accountAccessValidator.validate(aisConsent, false); assertTrue(actual.isValid()); }