### Question:
MBCategoryResolversImpl implements MBCategoryResolvers { @Override public DataFetcher<CompletableFuture<MBCategory>> getMBCategoryDataFetcher() { return environment -> { long categoryId = getCategoryId(environment); if (categoryId <= 0) { return null; } DataLoader<Long, MBCategory> dataLoader = environment.getDataLoader(MBCategoryBatchLoader.KEY); return dataLoader.load(categoryId); }; }  @Reference(unbind = "-") void setMBCategoryLocalService(MBCategoryLocalService mbCategoryLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<MBCategory>> getMBCategoriesDataFetcher(); @Override DataFetcher<CompletableFuture<MBCategory>> getMBCategoryDataFetcher(); @Override DataFetcher<MBCategory> createMBCategoryDataFetcher(); @Override DataFetcher<MBCategory> updateMBCategoryDataFetcher(); @Override DataFetcher<MBCategory> deleteMBCategoryDataFetcher();  }### Answer:
@Test public void getMBCategoryDataFetcher_should_return_the_searched_object() throws Exception { MBCategory expectedResult = mock(MBCategory.class); expectedResult.setCategoryId(CATEGORY_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("categoryId")) .thenReturn(CATEGORY_ID); when(dataLoader.load(CATEGORY_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<MBCategory> asyncResult = resolvers.getMBCategoryDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); MBCategory result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getMBCategoryDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("categoryId")) .thenReturn(0L); CompletableFuture<MBCategory> asyncResult = resolvers.getMBCategoryDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getMBCategoryDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("categoryId")) .thenReturn(CATEGORY_ID); when(dataLoader.load(CATEGORY_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<MBCategory> asyncResult = resolvers.getMBCategoryDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); MBCategory result = asyncResult.get(); assertNull(result); }