### Question:
ClassNameResolversImpl implements ClassNameResolvers { @Override public DataFetcher<CompletableFuture<ClassName>> getClassNameDataFetcher() { return environment -> { long classNameId = util.getLongArg(environment, "classNameId"); if (classNameId <= 0) { return null; } DataLoader<Long, ClassName> dataLoader = environment.getDataLoader(ClassNameBatchLoader.KEY); return dataLoader.load(classNameId); }; }  @Reference(unbind = "-") void setClassNameLocalService(ClassNameLocalService classnameLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<ClassName>> getClassNamesDataFetcher(); @Override DataFetcher<CompletableFuture<ClassName>> getClassNameDataFetcher(); @Override DataFetcher<ClassName> getClassNameByNameDataFetcher();  }### Answer:
@Test public void getClassNameDataFetcher_should_return_the_searched_object() throws Exception { ClassName expectedResult = mock(ClassName.class); expectedResult.setClassNameId(CLASS_NAME_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("classNameId")) .thenReturn(CLASS_NAME_ID); when(dataLoader.load(CLASS_NAME_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<ClassName> asyncResult = resolvers.getClassNameDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); ClassName result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getClassNameDataFetcher_no_specified_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("classNameId")) .thenReturn(0L); CompletableFuture<ClassName> asyncResult = resolvers.getClassNameDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getClassNameDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("classNameId")) .thenReturn(CLASS_NAME_ID); when(dataLoader.load(CLASS_NAME_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<ClassName> asyncResult = resolvers.getClassNameDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); ClassName result = asyncResult.get(); assertNull(result); }