### Question:
AssetTagResolversImpl implements AssetTagResolvers { @Override public DataFetcher<AssetTag> createAssetTagDataFetcher() { return environment -> { long userId = util.getLongArg(environment, "userId", util.getDefaultUserId()); long groupId = util.getLongArg(environment, "groupId"); String name = util.getStringArg(environment, "name"); ServiceContext serviceContext = new ServiceContext(); return assetTagLocalService.addTag( userId, groupId, name, serviceContext); }; }  @Reference(unbind = "-") void setAssetTagLocalService(AssetTagLocalService assetTagLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<AssetTag>> getAssetTagsDataFetcher(); @Override DataFetcher<List<AssetTag>> getAssetTagsForAssetDataFetcher(); @Override DataFetcher<CompletableFuture<AssetTag>> getAssetTagDataFetcher(); @Override DataFetcher<AssetTag> createAssetTagDataFetcher(); @Override DataFetcher<AssetTag> updateAssetTagDataFetcher(); @Override DataFetcher<AssetTag> deleteAssetTagDataFetcher();  }### Answer:
@Test public void createAssetTagDataFetcher_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userId", USER_ID); arguments.put("groupId", GROUP_ID); arguments.put("name", NAME); DataFetchingEnvironment environment = getTestEnvironment(arguments); AssetTag expectedResult = mock(AssetTag.class); expectedResult.setUserId(USER_ID); expectedResult.setTagId(TAG_ID); expectedResult.setGroupId(GROUP_ID); expectedResult.setName(NAME); useMockGraphQLUtil(environment, USER_ID, true); when(localService.addTag(eq(USER_ID), eq(GROUP_ID), eq(NAME), any(ServiceContext.class))) .thenReturn(expectedResult); AssetTag result = resolvers.createAssetTagDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void createAssetTagDataFetcher_without_user_id_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("groupId", GROUP_ID); arguments.put("name", NAME); DataFetchingEnvironment environment = getTestEnvironment(arguments); AssetTag expectedResult = mock(AssetTag.class); expectedResult.setUserId(DEFAULT_USER_ID); expectedResult.setTagId(TAG_ID); expectedResult.setGroupId(GROUP_ID); expectedResult.setName(NAME); useMockGraphQLUtil(environment, DEFAULT_USER_ID, true); when(localService.addTag(eq(DEFAULT_USER_ID), eq(GROUP_ID), eq(NAME), any(ServiceContext.class))) .thenReturn(expectedResult); AssetTag result = resolvers.createAssetTagDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = PortalException.class) public void createAssetTagDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, DEFAULT_USER_ID, false); when(localService.addTag(anyLong(), anyLong(), anyString(), any(ServiceContext.class))) .thenThrow(PortalException.class); AssetTag result = resolvers.createAssetTagDataFetcher() .get(environment); assertNull(result); }