### Question:
DDMStructureResolversImpl implements DDMStructureResolvers { @Override public DataFetcher<CompletableFuture<DDMStructure>> getDDMStructureDataFetcher() { return environment -> { long structureId = getStructureId(environment); if (structureId <= 0) { return null; } DataLoader<Long, DDMStructure> dataLoader = environment.getDataLoader(DDMStructureBatchLoader.KEY); return dataLoader.load(structureId); }; }  @Reference(unbind = "-") void setDDMStructureLocalService(DDMStructureLocalService ddmstructureLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<DDMStructure>> getDDMStructuresDataFetcher(); @Override DataFetcher<CompletableFuture<DDMStructure>> getDDMStructureDataFetcher(); @Override DataFetcher<DDMStructure> getDDMStructureByKeyDataFetcher(); @Override DataFetcher<DDMStructure> createDDMStructureDataFetcher(); @Override DataFetcher<DDMStructure> createDDMStructureForJournalArticleDataFetcher(); @Override DataFetcher<DDMStructure> updateDDMStructureDataFetcher(); @Override DataFetcher<DDMStructure> updateDDMStructureForJournalArticleDataFetcher(); @Override DataFetcher<DDMStructure> deleteDDMStructureDataFetcher();  }### Answer:
@Test public void getDDMStructureDataFetcher_should_return_the_searched_object() throws Exception { DDMStructure expectedResult = mock(DDMStructure.class); expectedResult.setStructureId(STRUCTURE_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("structureId")) .thenReturn(STRUCTURE_ID); when(dataLoader.load(STRUCTURE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<DDMStructure> asyncResult = resolvers.getDDMStructureDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); DDMStructure result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getDDMStructureDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("structureId")) .thenReturn(0L); CompletableFuture<DDMStructure> asyncResult = resolvers.getDDMStructureDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getDDMStructureDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("structureId")) .thenReturn(STRUCTURE_ID); when(dataLoader.load(STRUCTURE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<DDMStructure> asyncResult = resolvers.getDDMStructureDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); DDMStructure result = asyncResult.get(); assertNull(result); }