@Test public final void test_fetch_related_data() { List<Fund> expextedResult = new ArrayList<>(); expextedResult.add(getParentFund()); when(fundRepository.findById(any(Fund.class))).thenReturn(getParentFund()); List<Fund> actualResult = fundService.fetchRelated(getFunds()); assertEquals(expextedResult.get(0).getId(), actualResult.get(0).getParent().getId()); assertEquals(expextedResult.get(0).getName(), actualResult.get(0).getParent().getName()); }
public List<Fund> fetchRelated(List<Fund> funds) { for (Fund fund : funds) { fund.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (fund.getTenantId() != null) if (fund.getParent() != null && fund.getParent().getId() != null) { fund.getParent().setTenantId(fund.getTenantId()); Fund parentId = fundRepository.findById(fund.getParent()); if (parentId == null) { throw new InvalidDataException("parentId", ErrorCode.INVALID_REF_VALUE.getCode(), fund.getParent().getId()); } fund.setParent(parentId); } } return funds; }
FundService { public List<Fund> fetchRelated(List<Fund> funds) { for (Fund fund : funds) { fund.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (fund.getTenantId() != null) if (fund.getParent() != null && fund.getParent().getId() != null) { fund.getParent().setTenantId(fund.getTenantId()); Fund parentId = fundRepository.findById(fund.getParent()); if (parentId == null) { throw new InvalidDataException("parentId", ErrorCode.INVALID_REF_VALUE.getCode(), fund.getParent().getId()); } fund.setParent(parentId); } } return funds; } }
FundService { public List<Fund> fetchRelated(List<Fund> funds) { for (Fund fund : funds) { fund.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (fund.getTenantId() != null) if (fund.getParent() != null && fund.getParent().getId() != null) { fund.getParent().setTenantId(fund.getTenantId()); Fund parentId = fundRepository.findById(fund.getParent()); if (parentId == null) { throw new InvalidDataException("parentId", ErrorCode.INVALID_REF_VALUE.getCode(), fund.getParent().getId()); } fund.setParent(parentId); } } return funds; }  }
FundService { public List<Fund> fetchRelated(List<Fund> funds) { for (Fund fund : funds) { fund.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (fund.getTenantId() != null) if (fund.getParent() != null && fund.getParent().getId() != null) { fund.getParent().setTenantId(fund.getTenantId()); Fund parentId = fundRepository.findById(fund.getParent()); if (parentId == null) { throw new InvalidDataException("parentId", ErrorCode.INVALID_REF_VALUE.getCode(), fund.getParent().getId()); } fund.setParent(parentId); } } return funds; }  @Transactional List<Fund> create(List<Fund> funds, BindingResult errors, RequestInfo requestInfo); @Transactional List<Fund> update(List<Fund> funds, BindingResult errors, RequestInfo requestInfo); List<Fund> fetchRelated(List<Fund> funds); Pagination<Fund> search(FundSearch fundSearch, BindingResult errors); @Transactional Fund save(Fund fund); @Transactional Fund update(Fund fund); }
FundService { public List<Fund> fetchRelated(List<Fund> funds) { for (Fund fund : funds) { fund.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (fund.getTenantId() != null) if (fund.getParent() != null && fund.getParent().getId() != null) { fund.getParent().setTenantId(fund.getTenantId()); Fund parentId = fundRepository.findById(fund.getParent()); if (parentId == null) { throw new InvalidDataException("parentId", ErrorCode.INVALID_REF_VALUE.getCode(), fund.getParent().getId()); } fund.setParent(parentId); } } return funds; }  @Transactional List<Fund> create(List<Fund> funds, BindingResult errors, RequestInfo requestInfo); @Transactional List<Fund> update(List<Fund> funds, BindingResult errors, RequestInfo requestInfo); List<Fund> fetchRelated(List<Fund> funds); Pagination<Fund> search(FundSearch fundSearch, BindingResult errors); @Transactional Fund save(Fund fund); @Transactional Fund update(Fund fund);  }