### Question:
MBCategoryResolversImpl implements MBCategoryResolvers { @Override public DataFetcher<MBCategory> createMBCategoryDataFetcher() { return environment -> { long userId = util.getLongArg(environment, "userId", util.getDefaultUserId()); long parentCategoryId = util.getLongArg(environment, "parentCategoryId"); String name = util.getStringArg(environment, "name"); String description = util.getStringArg(environment, "description"); ServiceContext serviceContext = new ServiceContext(); return mbCategoryLocalService.addCategory( userId, parentCategoryId, name, description, serviceContext); }; }  @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 createMBCategoryDataFetcher_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userId", USER_ID); arguments.put("parentCategoryId", PARENT_CATEGORY_ID); arguments.put("name", NAME); arguments.put("description", DESCRIPTION); DataFetchingEnvironment environment = getTestEnvironment(arguments); MBCategory expectedResult = mock(MBCategory.class); expectedResult.setUserId(USER_ID); expectedResult.setCategoryId(CATEGORY_ID); expectedResult.setParentCategoryId(PARENT_CATEGORY_ID); expectedResult.setName(NAME); expectedResult.setDescription(DESCRIPTION); useMockGraphQLUtil(environment, USER_ID, true); when(localService.addCategory(eq(USER_ID), eq(PARENT_CATEGORY_ID), eq(NAME), eq(DESCRIPTION), any(ServiceContext.class))) .thenReturn(expectedResult); MBCategory result = resolvers.createMBCategoryDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void createMBCategoryDataFetcher_without_user_id_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("parentCategoryId", PARENT_CATEGORY_ID); arguments.put("name", NAME); arguments.put("description", DESCRIPTION); DataFetchingEnvironment environment = getTestEnvironment(arguments); MBCategory expectedResult = mock(MBCategory.class); expectedResult.setUserId(DEFAULT_USER_ID); expectedResult.setCategoryId(CATEGORY_ID); expectedResult.setParentCategoryId(PARENT_CATEGORY_ID); expectedResult.setName(NAME); expectedResult.setDescription(DESCRIPTION); useMockGraphQLUtil(environment, DEFAULT_USER_ID, true); when(localService.addCategory(eq(DEFAULT_USER_ID), eq(PARENT_CATEGORY_ID), eq(NAME), eq(DESCRIPTION), any(ServiceContext.class))) .thenReturn(expectedResult); MBCategory result = resolvers.createMBCategoryDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = PortalException.class) public void createMBCategoryDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, DEFAULT_USER_ID, false); when(localService.addCategory(anyLong(), anyLong(), anyString(), anyString(), any(ServiceContext.class))) .thenThrow(PortalException.class); MBCategory result = resolvers.createMBCategoryDataFetcher() .get(environment); assertNull(result); }