@Test public final void test_fetch_related_data() { List<BankAccount> expextedResult = new ArrayList<>(); List<BankAccount> bankAccounts = new ArrayList<>(); expextedResult.add(getBankAccount()); bankAccounts.add(getBankAccount()); when(bankBranchRepository.findById(any(BankBranch.class))).thenReturn(getBankBranch()); when(chartOfAccountRepository.findById(any(ChartOfAccount.class))).thenReturn(getChartOfAccount()); when(fundRepository.findById(any(Fund.class))).thenReturn(getFund()); List<BankAccount> actualResult = bankAccountService.fetchRelated(bankAccounts); assertEquals(expextedResult.get(0).getBankBranch().getId(), actualResult.get(0).getBankBranch().getId()); assertEquals(expextedResult.get(0).getFund().getId(), actualResult.get(0).getFund().getId()); assertEquals(expextedResult.get(0).getChartOfAccount().getId(), actualResult.get(0).getChartOfAccount().getId()); }
public List<BankAccount> fetchRelated(List<BankAccount> bankaccounts) { for (BankAccount bankAccount : bankaccounts) { bankAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankAccount.getBankBranch() != null) { BankBranch bankBranch = bankBranchRepository.findById(bankAccount.getBankBranch()); if (bankBranch == null) { throw new InvalidDataException("bankBranch", "bankBranch.invalid", " Invalid bankBranch"); } bankAccount.setBankBranch(bankBranch); } if (bankAccount.getChartOfAccount() != null) { ChartOfAccount chartOfAccount = chartOfAccountRepository.findById(bankAccount.getChartOfAccount()); if (chartOfAccount == null) { throw new InvalidDataException("chartOfAccount", "chartOfAccount.invalid", " Invalid chartOfAccount"); } bankAccount.setChartOfAccount(chartOfAccount); } if (bankAccount.getFund() != null) { Fund fund = fundRepository.findById(bankAccount.getFund()); if (fund == null) { throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); } bankAccount.setFund(fund); } } return bankaccounts; }
BankAccountService { public List<BankAccount> fetchRelated(List<BankAccount> bankaccounts) { for (BankAccount bankAccount : bankaccounts) { bankAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankAccount.getBankBranch() != null) { BankBranch bankBranch = bankBranchRepository.findById(bankAccount.getBankBranch()); if (bankBranch == null) { throw new InvalidDataException("bankBranch", "bankBranch.invalid", " Invalid bankBranch"); } bankAccount.setBankBranch(bankBranch); } if (bankAccount.getChartOfAccount() != null) { ChartOfAccount chartOfAccount = chartOfAccountRepository.findById(bankAccount.getChartOfAccount()); if (chartOfAccount == null) { throw new InvalidDataException("chartOfAccount", "chartOfAccount.invalid", " Invalid chartOfAccount"); } bankAccount.setChartOfAccount(chartOfAccount); } if (bankAccount.getFund() != null) { Fund fund = fundRepository.findById(bankAccount.getFund()); if (fund == null) { throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); } bankAccount.setFund(fund); } } return bankaccounts; } }
BankAccountService { public List<BankAccount> fetchRelated(List<BankAccount> bankaccounts) { for (BankAccount bankAccount : bankaccounts) { bankAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankAccount.getBankBranch() != null) { BankBranch bankBranch = bankBranchRepository.findById(bankAccount.getBankBranch()); if (bankBranch == null) { throw new InvalidDataException("bankBranch", "bankBranch.invalid", " Invalid bankBranch"); } bankAccount.setBankBranch(bankBranch); } if (bankAccount.getChartOfAccount() != null) { ChartOfAccount chartOfAccount = chartOfAccountRepository.findById(bankAccount.getChartOfAccount()); if (chartOfAccount == null) { throw new InvalidDataException("chartOfAccount", "chartOfAccount.invalid", " Invalid chartOfAccount"); } bankAccount.setChartOfAccount(chartOfAccount); } if (bankAccount.getFund() != null) { Fund fund = fundRepository.findById(bankAccount.getFund()); if (fund == null) { throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); } bankAccount.setFund(fund); } } return bankaccounts; }  }
BankAccountService { public List<BankAccount> fetchRelated(List<BankAccount> bankaccounts) { for (BankAccount bankAccount : bankaccounts) { bankAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankAccount.getBankBranch() != null) { BankBranch bankBranch = bankBranchRepository.findById(bankAccount.getBankBranch()); if (bankBranch == null) { throw new InvalidDataException("bankBranch", "bankBranch.invalid", " Invalid bankBranch"); } bankAccount.setBankBranch(bankBranch); } if (bankAccount.getChartOfAccount() != null) { ChartOfAccount chartOfAccount = chartOfAccountRepository.findById(bankAccount.getChartOfAccount()); if (chartOfAccount == null) { throw new InvalidDataException("chartOfAccount", "chartOfAccount.invalid", " Invalid chartOfAccount"); } bankAccount.setChartOfAccount(chartOfAccount); } if (bankAccount.getFund() != null) { Fund fund = fundRepository.findById(bankAccount.getFund()); if (fund == null) { throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); } bankAccount.setFund(fund); } } return bankaccounts; }  @Transactional List<BankAccount> create(List<BankAccount> bankAccounts, BindingResult errors, RequestInfo requestInfo); @Transactional List<BankAccount> update(List<BankAccount> bankAccounts, BindingResult errors, RequestInfo requestInfo); List<BankAccount> fetchRelated(List<BankAccount> bankaccounts); @Transactional List<BankAccount> update(List<BankAccount> bankaccounts, BindingResult errors); void addToQue(BankAccountRequest request); Pagination<BankAccount> search(BankAccountSearch bankAccountSearch, BindingResult errors); @Transactional BankAccount save(BankAccount bankAccount); @Transactional BankAccount update(BankAccount bankAccount); }
BankAccountService { public List<BankAccount> fetchRelated(List<BankAccount> bankaccounts) { for (BankAccount bankAccount : bankaccounts) { bankAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankAccount.getBankBranch() != null) { BankBranch bankBranch = bankBranchRepository.findById(bankAccount.getBankBranch()); if (bankBranch == null) { throw new InvalidDataException("bankBranch", "bankBranch.invalid", " Invalid bankBranch"); } bankAccount.setBankBranch(bankBranch); } if (bankAccount.getChartOfAccount() != null) { ChartOfAccount chartOfAccount = chartOfAccountRepository.findById(bankAccount.getChartOfAccount()); if (chartOfAccount == null) { throw new InvalidDataException("chartOfAccount", "chartOfAccount.invalid", " Invalid chartOfAccount"); } bankAccount.setChartOfAccount(chartOfAccount); } if (bankAccount.getFund() != null) { Fund fund = fundRepository.findById(bankAccount.getFund()); if (fund == null) { throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); } bankAccount.setFund(fund); } } return bankaccounts; }  @Transactional List<BankAccount> create(List<BankAccount> bankAccounts, BindingResult errors, RequestInfo requestInfo); @Transactional List<BankAccount> update(List<BankAccount> bankAccounts, BindingResult errors, RequestInfo requestInfo); List<BankAccount> fetchRelated(List<BankAccount> bankaccounts); @Transactional List<BankAccount> update(List<BankAccount> bankaccounts, BindingResult errors); void addToQue(BankAccountRequest request); Pagination<BankAccount> search(BankAccountSearch bankAccountSearch, BindingResult errors); @Transactional BankAccount save(BankAccount bankAccount); @Transactional BankAccount update(BankAccount bankAccount);  }