### Question:
MBCategoryResolversImpl implements MBCategoryResolvers { @Override public DataFetcher<MBCategory> deleteMBCategoryDataFetcher() { return environment -> { long categoryId = util.getLongArg(environment, "categoryId"); return mbCategoryLocalService.deleteMBCategory(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 deleteMBCategoryDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("categoryId", CATEGORY_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); MBCategory expectedResult = mock(MBCategory.class); expectedResult.setCategoryId(CATEGORY_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteMBCategory(eq(CATEGORY_ID))) .thenReturn(expectedResult); MBCategory result = resolvers.deleteMBCategoryDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchCategoryException.class) public void deleteMBCategoryDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); MBCategory expectedResult = mock(MBCategory.class); expectedResult.setCategoryId(CATEGORY_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteMBCategory(eq(CATEGORY_ID))) .thenThrow(NoSuchCategoryException.class); MBCategory result = resolvers.deleteMBCategoryDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchCategoryException.class) public void deleteMBCategoryDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("categoryId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); MBCategory expectedResult = mock(MBCategory.class); expectedResult.setCategoryId(CATEGORY_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("categoryId"))) .thenReturn(789456L); when(localService.deleteMBCategory(eq(789456L))) .thenThrow(NoSuchCategoryException.class); MBCategory result = resolvers.deleteMBCategoryDataFetcher() .get(environment); assertNull(result); }