### Question:
DDMContentResolversImpl implements DDMContentResolvers { @Override public DataFetcher<DDMContent> createDDMContentDataFetcher() { return environment -> { long userId = util.getLongArg(environment, "userId", util.getDefaultUserId()); long groupId = util.getLongArg(environment, "groupId"); String name = util.getStringArg(environment, "name"); String description = util.getStringArg(environment, "description"); String data = util.getStringArg(environment, "data"); ServiceContext serviceContext = new ServiceContext(); return ddmContentLocalService.addContent( userId, groupId, name, description, data, serviceContext); }; }  @Reference(unbind = "-") void setDDMContentLocalService(DDMContentLocalService ddmContentLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<DDMContent>> getDDMContentsDataFetcher(); @Override DataFetcher<CompletableFuture<DDMContent>> getDDMContentDataFetcher(); @Override DataFetcher<DDMContent> createDDMContentDataFetcher(); @Override DataFetcher<DDMContent> updateDDMContentDataFetcher(); @Override DataFetcher<DDMContent> deleteDDMContentDataFetcher();  }### Answer:
@Test public void createDDMContentDataFetcher_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); arguments.put("description", DESCRIPTION); arguments.put("data", DATA); DataFetchingEnvironment environment = getTestEnvironment(arguments); DDMContent expectedResult = mock(DDMContent.class); expectedResult.setUserId(USER_ID); expectedResult.setContentId(CONTENT_ID); expectedResult.setGroupId(GROUP_ID); expectedResult.setName(NAME); expectedResult.setDescription(DESCRIPTION); expectedResult.setData(DATA); useMockGraphQLUtil(environment, USER_ID, true); when(localService.addContent(eq(USER_ID), eq(GROUP_ID), eq(NAME), eq(DESCRIPTION), eq(DATA), any(ServiceContext.class))) .thenReturn(expectedResult); DDMContent result = resolvers.createDDMContentDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void createDDMContentDataFetcher_without_user_id_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("groupId", GROUP_ID); arguments.put("name", NAME); arguments.put("description", DESCRIPTION); arguments.put("data", DATA); DataFetchingEnvironment environment = getTestEnvironment(arguments); DDMContent expectedResult = mock(DDMContent.class); expectedResult.setUserId(DEFAULT_USER_ID); expectedResult.setContentId(CONTENT_ID); expectedResult.setGroupId(GROUP_ID); expectedResult.setName(NAME); expectedResult.setDescription(DESCRIPTION); expectedResult.setData(DATA); useMockGraphQLUtil(environment, DEFAULT_USER_ID, true); when(localService.addContent(eq(DEFAULT_USER_ID), eq(GROUP_ID), eq(NAME), eq(DESCRIPTION), eq(DATA), any(ServiceContext.class))) .thenReturn(expectedResult); DDMContent result = resolvers.createDDMContentDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = PortalException.class) public void createDDMContentDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, DEFAULT_USER_ID, false); when(localService.addContent(anyLong(), anyLong(), anyString(), anyString(), anyString(), any(ServiceContext.class))) .thenThrow(PortalException.class); DDMContent result = resolvers.createDDMContentDataFetcher() .get(environment); assertNull(result); }