### Question:
MBThreadResolversImpl implements MBThreadResolvers { @Override public DataFetcher<CompletableFuture<MBThread>> getMBThreadDataFetcher() { return environment -> { long threadId = getThreadId(environment); if (threadId <= 0) { return null; } DataLoader<Long, MBThread> dataLoader = environment.getDataLoader(MBThreadBatchLoader.KEY); return dataLoader.load(threadId); }; }  @Reference(unbind = "-") void setMBThreadLocalService(MBThreadLocalService mbThreadLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<MBThread>> getMBThreadsDataFetcher(); @Override DataFetcher<CompletableFuture<MBThread>> getMBThreadDataFetcher(); @Override DataFetcher<MBThread> createMBThreadDataFetcher(); @Override DataFetcher<MBThread> deleteMBThreadDataFetcher();  }### Answer:
@Test public void getMBThreadDataFetcher_should_return_the_searched_object() throws Exception { MBThread expectedResult = mock(MBThread.class); expectedResult.setThreadId(THREAD_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("threadId")) .thenReturn(THREAD_ID); when(dataLoader.load(THREAD_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<MBThread> asyncResult = resolvers.getMBThreadDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); MBThread result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getMBThreadDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("threadId")) .thenReturn(0L); CompletableFuture<MBThread> asyncResult = resolvers.getMBThreadDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getMBThreadDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("threadId")) .thenReturn(THREAD_ID); when(dataLoader.load(THREAD_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<MBThread> asyncResult = resolvers.getMBThreadDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); MBThread result = asyncResult.get(); assertNull(result); }