### Question:
JournalArticleResolversImpl implements JournalArticleResolvers { @Override public DataFetcher<CompletableFuture<JournalArticle>> getJournalArticleDataFetcher() { return environment -> { long id = util.getLongArg(environment, "id"); if (id <= 0) { return null; } DataLoader<Long, JournalArticle> dataLoader = environment.getDataLoader(JournalArticleBatchLoader.KEY); return dataLoader.load(id); }; }  @Reference(unbind = "-") void setJournalArticleLocalService(JournalArticleLocalService journalArticleLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<JournalArticle>> getJournalArticlesDataFetcher(); @Override DataFetcher<CompletableFuture<JournalArticle>> getJournalArticleDataFetcher(); @Override DataFetcher<JournalArticle> createJournalArticleDataFetcher(); @Override DataFetcher<JournalArticle> updateJournalArticleDataFetcher(); @Override DataFetcher<JournalArticle> deleteJournalArticleDataFetcher();  }### Answer:
@Test public void getJournalArticleDataFetcher_should_return_the_searched_object() throws Exception { JournalArticle expectedResult = mock(JournalArticle.class); expectedResult.setId(ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("id")) .thenReturn(ID); when(dataLoader.load(ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<JournalArticle> asyncResult = resolvers.getJournalArticleDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); JournalArticle result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getJournalArticleDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("id")) .thenReturn(0L); CompletableFuture<JournalArticle> asyncResult = resolvers.getJournalArticleDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getJournalArticleDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("id")) .thenReturn(ID); when(dataLoader.load(ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<JournalArticle> asyncResult = resolvers.getJournalArticleDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); JournalArticle result = asyncResult.get(); assertNull(result); }