### Question:
AssetCategoryResolversImpl implements AssetCategoryResolvers { @Override public DataFetcher<CompletableFuture<AssetCategory>> getAssetCategoryDataFetcher() { return environment -> { long categoryId = getCategoryId(environment); if (categoryId <= 0) { return null; } DataLoader<Long, AssetCategory> dataLoader = environment.getDataLoader(AssetCategoryBatchLoader.KEY); return dataLoader.load(categoryId); }; }  @Reference(unbind = "-") void setAssetCategoryLocalService(AssetCategoryLocalService assetCategoryLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<AssetCategory>> getAssetCategoriesDataFetcher(); @Override DataFetcher<List<AssetCategory>> getAssetCategoriesForAssetDataFetcher(); @Override DataFetcher<CompletableFuture<AssetCategory>> getAssetCategoryDataFetcher(); @Override DataFetcher<AssetCategory> createAssetCategoryDataFetcher(); @Override DataFetcher<AssetCategory> updateAssetCategoryDataFetcher(); @Override DataFetcher<AssetCategory> deleteAssetCategoryDataFetcher();  }### Answer:
@Test public void getAssetCategoryDataFetcher_should_return_the_searched_object() throws Exception { AssetCategory expectedResult = mock(AssetCategory.class); expectedResult.setCategoryId(CATEGORY_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("categoryId")) .thenReturn(CATEGORY_ID); when(dataLoader.load(CATEGORY_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<AssetCategory> asyncResult = resolvers.getAssetCategoryDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); AssetCategory result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getAssetCategoryDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("categoryId")) .thenReturn(0L); CompletableFuture<AssetCategory> asyncResult = resolvers.getAssetCategoryDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getAssetCategoryDataFetcher_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<AssetCategory> asyncResult = resolvers.getAssetCategoryDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); AssetCategory result = asyncResult.get(); assertNull(result); }