### Question:
DDMTemplateResolversImpl implements DDMTemplateResolvers { @Override public DataFetcher<CompletableFuture<DDMTemplate>> getDDMTemplateDataFetcher() { return environment -> { long templateId = util.getLongArg(environment, "templateId"); if (templateId <= 0) { return null; } DataLoader<Long, DDMTemplate> dataLoader = environment.getDataLoader(DDMTemplateBatchLoader.KEY); return dataLoader.load(templateId); }; }  @Reference(unbind = "-") void setDDMTemplateLocalService(DDMTemplateLocalService ddmTemplateLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<DDMTemplate>> getDDMTemplatesDataFetcher(); @Override DataFetcher<CompletableFuture<DDMTemplate>> getDDMTemplateDataFetcher(); @Override DataFetcher<DDMTemplate> getDDMTemplateByKeyDataFetcher(); @Override DataFetcher<DDMTemplate> createDDMTemplateDataFetcher(); @Override DataFetcher<DDMTemplate> updateDDMTemplateDataFetcher(); @Override DataFetcher<DDMTemplate> deleteDDMTemplateDataFetcher();  }### Answer:
@Test public void getDDMTemplateDataFetcher_should_return_the_searched_object() throws Exception { DDMTemplate expectedResult = mock(DDMTemplate.class); expectedResult.setTemplateId(TEMPLATE_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("templateId")) .thenReturn(TEMPLATE_ID); when(dataLoader.load(TEMPLATE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<DDMTemplate> asyncResult = resolvers.getDDMTemplateDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); DDMTemplate result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getDDMTemplateDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("templateId")) .thenReturn(0L); CompletableFuture<DDMTemplate> asyncResult = resolvers.getDDMTemplateDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getDDMTemplateDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("templateId")) .thenReturn(TEMPLATE_ID); when(dataLoader.load(TEMPLATE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<DDMTemplate> asyncResult = resolvers.getDDMTemplateDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); DDMTemplate result = asyncResult.get(); assertNull(result); }