### Question:
WebsiteResolversImpl implements WebsiteResolvers { @Override public DataFetcher<Website> createWebsiteDataFetcher() { return environment -> { long userId = util.getLongArg(environment, "userId", util.getDefaultUserId()); String className = util.getStringArg(environment, "className"); long classPK = util.getLongArg(environment, "classPK"); String url = util.getStringArg(environment, "url"); long typeId = util.getLongArg(environment, "typeId"); boolean primary = util.getBooleanArg(environment, "primary"); ServiceContext serviceContext = new ServiceContext(); return websiteLocalService.addWebsite( userId, className, classPK, url, typeId, primary, serviceContext); }; }  @Reference(unbind = "-") void setWebsiteLocalService(WebsiteLocalService websiteLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Website>> getWebsitesDataFetcher(); @Override DataFetcher<List<Website>> getWebsitesForEntityDataFetcher(); @Override DataFetcher<CompletableFuture<Website>> getWebsiteDataFetcher(); @Override DataFetcher<Website> createWebsiteDataFetcher(); @Override DataFetcher<Website> updateWebsiteDataFetcher(); @Override DataFetcher<Website> deleteWebsiteDataFetcher();  }### Answer:
@Test public void createWebsiteDataFetcher_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("userId", USER_ID); arguments.put("className", CLASS_NAME); arguments.put("classPK", CLASS_PK); arguments.put("url", URL); arguments.put("typeId", TYPE_ID); arguments.put("primary", PRIMARY); DataFetchingEnvironment environment = getTestEnvironment(arguments); Website expectedResult = mock(Website.class); expectedResult.setUserId(USER_ID); expectedResult.setClassName(CLASS_NAME); expectedResult.setClassPK(CLASS_PK); expectedResult.setUrl(URL); expectedResult.setTypeId(TYPE_ID); expectedResult.setPrimary(PRIMARY); useMockGraphQLUtil(environment, USER_ID, true); when(localService.addWebsite(eq(USER_ID), eq(CLASS_NAME), eq(CLASS_PK), eq(URL), eq(TYPE_ID), eq(PRIMARY), any(ServiceContext.class))) .thenReturn(expectedResult); Website result = resolvers.createWebsiteDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void createWebsiteDataFetcher_without_user_id_should_return_new_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("className", CLASS_NAME); arguments.put("classPK", CLASS_PK); arguments.put("url", URL); arguments.put("typeId", TYPE_ID); arguments.put("primary", PRIMARY); DataFetchingEnvironment environment = getTestEnvironment(arguments); Website expectedResult = mock(Website.class); expectedResult.setUserId(DEFAULT_USER_ID); expectedResult.setClassName(CLASS_NAME); expectedResult.setClassPK(CLASS_PK); expectedResult.setUrl(URL); expectedResult.setTypeId(TYPE_ID); expectedResult.setPrimary(PRIMARY); useMockGraphQLUtil(environment, DEFAULT_USER_ID, true); when(localService.addWebsite(eq(DEFAULT_USER_ID), eq(CLASS_NAME), eq(CLASS_PK), eq(URL), eq(TYPE_ID), eq(PRIMARY), any(ServiceContext.class))) .thenReturn(expectedResult); Website result = resolvers.createWebsiteDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = PortalException.class) public void createWebsiteDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, DEFAULT_USER_ID, false); when(localService.addWebsite(anyLong(), anyString(), anyLong(), anyString(), anyLong(), anyBoolean(), any(ServiceContext.class))) .thenThrow(PortalException.class); Website result = resolvers.createWebsiteDataFetcher() .get(environment); assertNull(result); }