### Question:
AccountAccessUpdater { @NotNull public AccountAccess updateAccountReferencesInAccess(@NotNull AccountAccess existingAccess, @NotNull AccountAccess newAccess) { if (hasNoAccountReferences(existingAccess)) { return new AccountAccess(newAccess.getAccounts(), newAccess.getBalances(), newAccess.getTransactions(), newAccess.getAdditionalInformationAccess()); } List<AccountReference> updatedAccounts = existingAccess.getAccounts().stream() .map(ref -> updateAccountReference(ref, newAccess.getAccounts())) .collect(Collectors.toList()); List<AccountReference> updatedBalances = existingAccess.getBalances().stream() .map(ref -> updateAccountReference(ref, newAccess.getBalances())) .collect(Collectors.toList()); List<AccountReference> updatedTransactions = existingAccess.getTransactions().stream() .map(ref -> updateAccountReference(ref, newAccess.getTransactions())) .collect(Collectors.toList()); AdditionalInformationAccess updatedAdditionalInformation = updateAccountReferencesInAdditionalInformation(existingAccess.getAdditionalInformationAccess(), newAccess.getAdditionalInformationAccess()); return new AccountAccess(updatedAccounts, updatedBalances, updatedTransactions, updatedAdditionalInformation); }  @NotNull AccountAccess updateAccountReferencesInAccess(@NotNull AccountAccess existingAccess,
                                                         @NotNull AccountAccess newAccess);  }### Answer:
@Test void updateAccountReferencesInAccess() { AccountAccess existingAccess = jsonReader.getObjectFromFile("json/service/account/account-access.json", AccountAccess.class); AccountAccess newAccess = jsonReader.getObjectFromFile("json/service/account/account-access-aspsp.json", AccountAccess.class); AccountAccess updatedAccess = accountAccessUpdater.updateAccountReferencesInAccess(existingAccess, newAccess); assertEquals(newAccess, updatedAccess); }
@Test void updateAccountReferencesInAccess_additionalInformationReferences() { AccountAccess existingAccess = jsonReader.getObjectFromFile("json/service/account/account-access-additional-info.json", AccountAccess.class); AccountAccess newAccess = jsonReader.getObjectFromFile("json/service/account/account-access-additional-info-aspsp.json", AccountAccess.class); AccountAccess updatedAccess = accountAccessUpdater.updateAccountReferencesInAccess(existingAccess, newAccess); assertEquals(newAccess, updatedAccess); }
@Test void updateAccountReferencesInAccess_noExistingReferences() { AccountAccess existingAccess = jsonReader.getObjectFromFile("json/service/account/account-access-no-references.json", AccountAccess.class); AccountAccess newAccess = jsonReader.getObjectFromFile("json/service/account/account-access-aspsp.json", AccountAccess.class); AccountAccess expectedAccess = jsonReader.getObjectFromFile("json/service/account/account-access-aspsp.json", AccountAccess.class); AccountAccess updatedAccess = accountAccessUpdater.updateAccountReferencesInAccess(existingAccess, newAccess); assertEquals(expectedAccess, updatedAccess); }
@Test void updateAccountReferencesInAccess_ignoreExtraReferences() { AccountAccess existingAccess = jsonReader.getObjectFromFile("json/service/account/account-access.json", AccountAccess.class); AccountAccess newAccess = jsonReader.getObjectFromFile("json/service/account/account-access-aspsp-extra-references.json", AccountAccess.class); AccountAccess expectedAccess = jsonReader.getObjectFromFile("json/service/account/account-access-extra-updated.json", AccountAccess.class); AccountAccess updatedAccess = accountAccessUpdater.updateAccountReferencesInAccess(existingAccess, newAccess); assertEquals(expectedAccess, updatedAccess); }