@Test public final void test_fetch_related_data() { List<BankBranch> expextedResult = new ArrayList<>(); List<BankBranch> bankBranches = new ArrayList<>(); expextedResult.add(getBankBranch()); bankBranches.add(getBankBranch()); when(bankRepository.findById(any(Bank.class))).thenReturn(getBank()); List<BankBranch> actualResult = bankBranchService.fetchRelated(bankBranches); assertEquals(expextedResult.get(0).getBank().getId(), actualResult.get(0).getBank().getId()); }
public List<BankBranch> fetchRelated(List<BankBranch> bankbranches) { for (BankBranch bankBranch : bankbranches) { bankBranch.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankBranch.getTenantId() != null) if (bankBranch.getBank() != null && bankBranch.getBank().getId() != null) { bankBranch.getBank().setTenantId(bankBranch.getTenantId()); Bank bank = bankRepository.findById(bankBranch.getBank()); if (bank == null) { throw new InvalidDataException("bank", "bank.invalid", " Invalid bank"); } bankBranch.setBank(bank); } } return bankbranches; }
BankBranchService { public List<BankBranch> fetchRelated(List<BankBranch> bankbranches) { for (BankBranch bankBranch : bankbranches) { bankBranch.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankBranch.getTenantId() != null) if (bankBranch.getBank() != null && bankBranch.getBank().getId() != null) { bankBranch.getBank().setTenantId(bankBranch.getTenantId()); Bank bank = bankRepository.findById(bankBranch.getBank()); if (bank == null) { throw new InvalidDataException("bank", "bank.invalid", " Invalid bank"); } bankBranch.setBank(bank); } } return bankbranches; } }
BankBranchService { public List<BankBranch> fetchRelated(List<BankBranch> bankbranches) { for (BankBranch bankBranch : bankbranches) { bankBranch.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankBranch.getTenantId() != null) if (bankBranch.getBank() != null && bankBranch.getBank().getId() != null) { bankBranch.getBank().setTenantId(bankBranch.getTenantId()); Bank bank = bankRepository.findById(bankBranch.getBank()); if (bank == null) { throw new InvalidDataException("bank", "bank.invalid", " Invalid bank"); } bankBranch.setBank(bank); } } return bankbranches; }  }
BankBranchService { public List<BankBranch> fetchRelated(List<BankBranch> bankbranches) { for (BankBranch bankBranch : bankbranches) { bankBranch.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankBranch.getTenantId() != null) if (bankBranch.getBank() != null && bankBranch.getBank().getId() != null) { bankBranch.getBank().setTenantId(bankBranch.getTenantId()); Bank bank = bankRepository.findById(bankBranch.getBank()); if (bank == null) { throw new InvalidDataException("bank", "bank.invalid", " Invalid bank"); } bankBranch.setBank(bank); } } return bankbranches; }  @Transactional List<BankBranch> create(List<BankBranch> bankBranches, BindingResult errors, RequestInfo requestInfo); @Transactional List<BankBranch> update(List<BankBranch> bankBranches, BindingResult errors, RequestInfo requestInfo); List<BankBranch> fetchRelated(List<BankBranch> bankbranches); @Transactional List<BankBranch> update(List<BankBranch> bankbranches, BindingResult errors); Pagination<BankBranch> search(BankBranchSearch bankBranchSearch, BindingResult errors); @Transactional BankBranch save(BankBranch bankBranch); @Transactional BankBranch update(BankBranch bankBranch); }
BankBranchService { public List<BankBranch> fetchRelated(List<BankBranch> bankbranches) { for (BankBranch bankBranch : bankbranches) { bankBranch.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (bankBranch.getTenantId() != null) if (bankBranch.getBank() != null && bankBranch.getBank().getId() != null) { bankBranch.getBank().setTenantId(bankBranch.getTenantId()); Bank bank = bankRepository.findById(bankBranch.getBank()); if (bank == null) { throw new InvalidDataException("bank", "bank.invalid", " Invalid bank"); } bankBranch.setBank(bank); } } return bankbranches; }  @Transactional List<BankBranch> create(List<BankBranch> bankBranches, BindingResult errors, RequestInfo requestInfo); @Transactional List<BankBranch> update(List<BankBranch> bankBranches, BindingResult errors, RequestInfo requestInfo); List<BankBranch> fetchRelated(List<BankBranch> bankbranches); @Transactional List<BankBranch> update(List<BankBranch> bankbranches, BindingResult errors); Pagination<BankBranch> search(BankBranchSearch bankBranchSearch, BindingResult errors); @Transactional BankBranch save(BankBranch bankBranch); @Transactional BankBranch update(BankBranch bankBranch);  }