### Question:
PermittedAccountReferenceValidator { public ValidationResult validate(AisConsent aisConsent, String accountId, boolean withBalance) { AccountAccess accountAccess = aisConsent.getAspspAccountAccesses(); List<AccountReference> accountReferences = withBalance ? accountAccess.getBalances() : accountAccess.getAccounts(); return accountReferenceAccessValidator.validate(aisConsent, accountReferences, accountId, aisConsent.getAisConsentRequestType()); }  ValidationResult validate(AisConsent aisConsent, String accountId, boolean withBalance);  }### Answer:
@Test void validate_withBalanceIsTrue_success() { ValidationResult validationResult = validator.validate(aisConsent, ACCOUNT_ID, true); assertTrue(validationResult.isValid()); }
@Test void validate_withBalanceIsFalse_success() { ValidationResult validationResult = validator.validate(aisConsent, ACCOUNT_ID, false); assertTrue(validationResult.isValid()); }
@Test void validate_withBalanceIsTrue_notValidByAccountId() { ValidationResult validationResult = validator.validate(aisConsent, WRONG_ACCOUNT_ID, true); assertFalse(validationResult.isValid()); assertEquals(ErrorType.AIS_401, validationResult.getMessageError().getErrorType()); assertEquals(CONSENT_INVALID, validationResult.getMessageError().getTppMessage().getMessageErrorCode()); }
@Test void validate_withBalanceIsFalse_notValidByAccountId() { ValidationResult validationResult = validator.validate(aisConsent, WRONG_ACCOUNT_ID, false); assertFalse(validationResult.isValid()); assertEquals(ErrorType.AIS_401, validationResult.getMessageError().getErrorType()); assertEquals(CONSENT_INVALID, validationResult.getMessageError().getTppMessage().getMessageErrorCode()); }