@Test(expected = InvalidDataException.class) public final void test_fetch_related_data_when_parentid_is_wrong() { List<Function> expextedResult = new ArrayList<>(); expextedResult.add(getParentFunction()); List<Function> functions = new ArrayList<>(); functions.add(getFunction()); ApplicationThreadLocals.setTenantId("default"); when(functionRepository.findById(any(Function.class))).thenReturn(null); functionService.fetchRelated(functions); }
public List<Function> fetchRelated(List<Function> functions) { for (Function function : functions) { function.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (function.getTenantId() != null) if (function.getParentId() != null && function.getParentId().getId() != null) { function.getParentId().setTenantId(function.getTenantId()); Function parentId = functionRepository.findById(function.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } function.setParentId(parentId); } } return functions; }
FunctionService { public List<Function> fetchRelated(List<Function> functions) { for (Function function : functions) { function.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (function.getTenantId() != null) if (function.getParentId() != null && function.getParentId().getId() != null) { function.getParentId().setTenantId(function.getTenantId()); Function parentId = functionRepository.findById(function.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } function.setParentId(parentId); } } return functions; } }
FunctionService { public List<Function> fetchRelated(List<Function> functions) { for (Function function : functions) { function.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (function.getTenantId() != null) if (function.getParentId() != null && function.getParentId().getId() != null) { function.getParentId().setTenantId(function.getTenantId()); Function parentId = functionRepository.findById(function.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } function.setParentId(parentId); } } return functions; }  }
FunctionService { public List<Function> fetchRelated(List<Function> functions) { for (Function function : functions) { function.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (function.getTenantId() != null) if (function.getParentId() != null && function.getParentId().getId() != null) { function.getParentId().setTenantId(function.getTenantId()); Function parentId = functionRepository.findById(function.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } function.setParentId(parentId); } } return functions; }  @Transactional List<Function> create(List<Function> functions, BindingResult errors, RequestInfo requestInfo); @Transactional List<Function> update(List<Function> functions, BindingResult errors, RequestInfo requestInfo); List<Function> fetchRelated(List<Function> functions); Pagination<Function> search(FunctionSearch functionSearch, BindingResult errors); @Transactional Function save(Function function); @Transactional Function update(Function function); }
FunctionService { public List<Function> fetchRelated(List<Function> functions) { for (Function function : functions) { function.setTenantId(ApplicationThreadLocals.getTenantId().get()); if (function.getTenantId() != null) if (function.getParentId() != null && function.getParentId().getId() != null) { function.getParentId().setTenantId(function.getTenantId()); Function parentId = functionRepository.findById(function.getParentId()); if (parentId == null) { throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId"); } function.setParentId(parentId); } } return functions; }  @Transactional List<Function> create(List<Function> functions, BindingResult errors, RequestInfo requestInfo); @Transactional List<Function> update(List<Function> functions, BindingResult errors, RequestInfo requestInfo); List<Function> fetchRelated(List<Function> functions); Pagination<Function> search(FunctionSearch functionSearch, BindingResult errors); @Transactional Function save(Function function); @Transactional Function update(Function function);  }