@Test public final void testFetchRelated() { when(accountCodePurposeRepository.findById(any(AccountCodePurpose.class))).thenReturn(getAccountCodePurpose()); when(chartOfAccountRepository.findById(any(ChartOfAccount.class))).thenReturn(getChartOfAccount()); chartOfAccounts.add(getChartOfAccount()); chartOfAccountService.fetchRelated(chartOfAccounts); }
public List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts) { for (ChartOfAccount chartOfAccount : chartofaccounts) { chartOfAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (chartOfAccount.getAccountCodePurpose() != null) { AccountCodePurpose accountCodePurpose = accountCodePurposeRepository .findById(chartOfAccount.getAccountCodePurpose()); if (accountCodePurpose == null) { throw new InvalidDataException("accountCodePurpose", "accountCodePurpose.invalid", " Invalid accountCodePurpose"); } chartOfAccount.setAccountCodePurpose(accountCodePurpose); } if (chartOfAccount.getParentId() != null) { ChartOfAccount parentId = chartOfAccountRepository.findById(chartOfAccount.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } chartOfAccount.setParentId(parentId); } } return chartofaccounts; }
ChartOfAccountService { public List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts) { for (ChartOfAccount chartOfAccount : chartofaccounts) { chartOfAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (chartOfAccount.getAccountCodePurpose() != null) { AccountCodePurpose accountCodePurpose = accountCodePurposeRepository .findById(chartOfAccount.getAccountCodePurpose()); if (accountCodePurpose == null) { throw new InvalidDataException("accountCodePurpose", "accountCodePurpose.invalid", " Invalid accountCodePurpose"); } chartOfAccount.setAccountCodePurpose(accountCodePurpose); } if (chartOfAccount.getParentId() != null) { ChartOfAccount parentId = chartOfAccountRepository.findById(chartOfAccount.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } chartOfAccount.setParentId(parentId); } } return chartofaccounts; } }
ChartOfAccountService { public List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts) { for (ChartOfAccount chartOfAccount : chartofaccounts) { chartOfAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (chartOfAccount.getAccountCodePurpose() != null) { AccountCodePurpose accountCodePurpose = accountCodePurposeRepository .findById(chartOfAccount.getAccountCodePurpose()); if (accountCodePurpose == null) { throw new InvalidDataException("accountCodePurpose", "accountCodePurpose.invalid", " Invalid accountCodePurpose"); } chartOfAccount.setAccountCodePurpose(accountCodePurpose); } if (chartOfAccount.getParentId() != null) { ChartOfAccount parentId = chartOfAccountRepository.findById(chartOfAccount.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } chartOfAccount.setParentId(parentId); } } return chartofaccounts; }  }
ChartOfAccountService { public List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts) { for (ChartOfAccount chartOfAccount : chartofaccounts) { chartOfAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (chartOfAccount.getAccountCodePurpose() != null) { AccountCodePurpose accountCodePurpose = accountCodePurposeRepository .findById(chartOfAccount.getAccountCodePurpose()); if (accountCodePurpose == null) { throw new InvalidDataException("accountCodePurpose", "accountCodePurpose.invalid", " Invalid accountCodePurpose"); } chartOfAccount.setAccountCodePurpose(accountCodePurpose); } if (chartOfAccount.getParentId() != null) { ChartOfAccount parentId = chartOfAccountRepository.findById(chartOfAccount.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } chartOfAccount.setParentId(parentId); } } return chartofaccounts; }  List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts); @Transactional List<ChartOfAccount> add(List<ChartOfAccount> chartofaccounts, BindingResult errors); @Transactional List<ChartOfAccount> update(List<ChartOfAccount> chartofaccounts, BindingResult errors); void addToQue(ChartOfAccountRequest request); Pagination<ChartOfAccount> search(ChartOfAccountSearch chartOfAccountSearch, BindingResult errors); @Transactional ChartOfAccount save(ChartOfAccount chartOfAccount); @Transactional ChartOfAccount update(ChartOfAccount chartOfAccount); }
ChartOfAccountService { public List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts) { for (ChartOfAccount chartOfAccount : chartofaccounts) { chartOfAccount.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (chartOfAccount.getAccountCodePurpose() != null) { AccountCodePurpose accountCodePurpose = accountCodePurposeRepository .findById(chartOfAccount.getAccountCodePurpose()); if (accountCodePurpose == null) { throw new InvalidDataException("accountCodePurpose", "accountCodePurpose.invalid", " Invalid accountCodePurpose"); } chartOfAccount.setAccountCodePurpose(accountCodePurpose); } if (chartOfAccount.getParentId() != null) { ChartOfAccount parentId = chartOfAccountRepository.findById(chartOfAccount.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } chartOfAccount.setParentId(parentId); } } return chartofaccounts; }  List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts); @Transactional List<ChartOfAccount> add(List<ChartOfAccount> chartofaccounts, BindingResult errors); @Transactional List<ChartOfAccount> update(List<ChartOfAccount> chartofaccounts, BindingResult errors); void addToQue(ChartOfAccountRequest request); Pagination<ChartOfAccount> search(ChartOfAccountSearch chartOfAccountSearch, BindingResult errors); @Transactional ChartOfAccount save(ChartOfAccount chartOfAccount); @Transactional ChartOfAccount update(ChartOfAccount chartOfAccount);  }