### Question:
UserGroupResolversImpl implements UserGroupResolvers { @Override public DataFetcher<UserGroup> createUserGroupDataFetcher() { return environment -> { long userId = util.getLongArg(environment, "userId", util.getDefaultUserId()); long companyId = util.getLongArg(environment, "companyId"); String name = util.getStringArg(environment, "name"); String description = util.getStringArg(environment, "description"); ServiceContext serviceContext = new ServiceContext(); return usergroupLocalService.addUserGroup( userId, companyId, name, description, serviceContext); }; }  @Reference(unbind = "-") void setUserGroupLocalService(UserGroupLocalService usergroupLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<UserGroup>> getUserGroupsDataFetcher(); @Override DataFetcher<CompletableFuture<UserGroup>> getUserGroupDataFetcher(); @Override DataFetcher<UserGroup> getUserGroupByNameDataFetcher(); @Override DataFetcher<UserGroup> createUserGroupDataFetcher(); @Override DataFetcher<UserGroup> updateUserGroupDataFetcher(); @Override DataFetcher<UserGroup> deleteUserGroupDataFetcher();  }### Answer:
@Test public void createUserGroupDataFetcher_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userId", USER_ID); arguments.put("companyId", COMPANY_ID); arguments.put("name", NAME); arguments.put("description", DESCRIPTION); DataFetchingEnvironment environment = getTestEnvironment(arguments); UserGroup expectedResult = mock(UserGroup.class); expectedResult.setUserId(USER_ID); expectedResult.setCompanyId(COMPANY_ID); expectedResult.setName(NAME); expectedResult.setDescription(DESCRIPTION); useMockGraphQLUtil(environment, USER_ID, true); when(localService.addUserGroup(eq(USER_ID), eq(COMPANY_ID), eq(NAME), eq(DESCRIPTION), any(ServiceContext.class))) .thenReturn(expectedResult); UserGroup result = resolvers.createUserGroupDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void createUserGroupDataFetcher_without_user_id_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("companyId", COMPANY_ID); arguments.put("name", NAME); arguments.put("description", DESCRIPTION); DataFetchingEnvironment environment = getTestEnvironment(arguments); UserGroup expectedResult = mock(UserGroup.class); expectedResult.setUserId(DEFAULT_USER_ID); expectedResult.setCompanyId(COMPANY_ID); expectedResult.setName(NAME); expectedResult.setDescription(DESCRIPTION); useMockGraphQLUtil(environment, DEFAULT_USER_ID, true); when(localService.addUserGroup(eq(DEFAULT_USER_ID), eq(COMPANY_ID), eq(NAME), eq(DESCRIPTION), any(ServiceContext.class))) .thenReturn(expectedResult); UserGroup result = resolvers.createUserGroupDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = PortalException.class) public void createUserGroupDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, DEFAULT_USER_ID, false); when(localService.addUserGroup(anyLong(), anyLong(), anyString(), anyString(), any(ServiceContext.class))) .thenThrow(PortalException.class); UserGroup result = resolvers.createUserGroupDataFetcher() .get(environment); assertNull(result); }