### Question:
DesignatorToAccountIdentifierMapper { public Stream<AccountAssignment> getLedgersNeedingAccounts() { final Set<String> accountAssignmentGroups = IndividualLendingPatternFactory.individualLendingPattern().getAccountAssignmentGroups(); final Set<RequiredAccountAssignment> accountAssignmentsRequired = IndividualLendingPatternFactory.individualLendingPattern().getAccountAssignmentsRequired(); final Map<String, RequiredAccountAssignment> accountAssignmentsRequiredMap = accountAssignmentsRequired.stream().collect(Collectors.toMap(RequiredAccountAssignment::getAccountDesignator, x -> x)); final Map<String, String> accountAssignmentAlternativeAccountIdsMap = oneTimeAccountAssignments.stream() .filter(x -> x.getAlternativeAccountNumber() != null) .collect(Collectors.toMap(AccountAssignment::getDesignator, AccountAssignment::getAlternativeAccountNumber)); final Map<String, String> existingAccountsAssignmentsMap = oneTimeAccountAssignments.stream() .filter(x -> x.getAccountIdentifier() != null) .collect(Collectors.toMap(AccountAssignment::getDesignator, AccountAssignment::getAccountIdentifier)); final Map<String, Optional<String>> groupToLedgerMapping = accountAssignmentGroups.stream() .collect(Collectors.toMap( Function.identity(), group -> mapToCaseAccountAssignment(group).map(AccountAssignment::getAccountIdentifier))); final Stream<AccountAssignment> ledgerAccountAssignments = productAccountAssignmentsAsStream() .filter(x -> !x.getDesignator().equals(AccountDesignators.ENTRY)) .filter(x -> (x.getAccountIdentifier() == null) && (x.getLedgerIdentifier() != null)); return ledgerAccountAssignments .map(ledgerAccountAssignment -> { final AccountAssignment ret = new AccountAssignment(ledgerAccountAssignment); ret.setAlternativeAccountNumber(accountAssignmentAlternativeAccountIdsMap.get(ledgerAccountAssignment.getDesignator())); final String existingAccountSetting = existingAccountsAssignmentsMap.get(ledgerAccountAssignment.getDesignator()); if (existingAccountSetting != null) ret.setAccountIdentifier(existingAccountSetting); final Optional<String> accountAssignmentGroup = Optional.ofNullable(accountAssignmentsRequiredMap.get(ledgerAccountAssignment.getDesignator())).map(RequiredAccountAssignment::getGroup); final Optional<String> changedLedger = accountAssignmentGroup.flatMap(groupToLedgerMapping::get); changedLedger.ifPresent(ret::setLedgerIdentifier); return ret; }); } DesignatorToAccountIdentifierMapper(final @Nonnull DataContextOfAction dataContextOfAction);   DesignatorToAccountIdentifierMapper(
      final @Nonnull Set<ProductAccountAssignmentEntity> productAccountAssignments,
      final @Nonnull Set<CaseAccountAssignmentEntity> caseAccountAssignments,
      final @Nonnull List<AccountAssignment> oneTimeAccountAssignments); Optional<String> map(final @Nonnull String accountDesignator); String mapOrThrow(final @Nonnull String accountDesignator); Stream<GroupNeedingLedger> getGroupsNeedingLedgers(); Stream<AccountAssignment> getLedgersNeedingAccounts();  }### Answer:
@Test public void getLedgersNeedingAccounts() { final Set<AccountAssignment> ret = testSubject.getLedgersNeedingAccounts().collect(Collectors.toSet()); Assert.assertEquals(testCase.expectedLedgersNeedingAccounts, ret); }