### Question:
CompanyResolversImpl implements CompanyResolvers { @Override public DataFetcher<CompletableFuture<Company>> getCompanyDataFetcher() { return environment -> { long companyId = getCompanyId(environment); if (companyId <= 0) { return null; } DataLoader<Long, Company> dataLoader = environment.getDataLoader(CompanyBatchLoader.KEY); return dataLoader.load(companyId); }; }  @Reference(unbind = "-") void setCompanyLocalService(CompanyLocalService companyLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Company>> getCompaniesDataFetcher(); @Override DataFetcher<CompletableFuture<Company>> getCompanyDataFetcher(); @Override DataFetcher<Company> getCompanyByWebIdDataFetcher(); @Override DataFetcher<Company> createCompanyDataFetcher(); @Override DataFetcher<Company> updateCompanyDataFetcher(); @Override DataFetcher<Company> deleteCompanyDataFetcher();  }### Answer:
@Test public void getCompanyDataFetcher_should_return_the_searched_object() throws Exception { Company expectedResult = mock(Company.class); expectedResult.setCompanyId(COMPANY_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("companyId")) .thenReturn(COMPANY_ID); when(dataLoader.load(COMPANY_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<Company> asyncResult = resolvers.getCompanyDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Company result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getCompanyDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("companyId")) .thenReturn(0L); CompletableFuture<Company> asyncResult = resolvers.getCompanyDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getCompanyDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("companyId")) .thenReturn(COMPANY_ID); when(dataLoader.load(COMPANY_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<Company> asyncResult = resolvers.getCompanyDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Company result = asyncResult.get(); assertNull(result); }