### Question:
RatingsEntryResolversImpl implements RatingsEntryResolvers { @Override public DataFetcher<RatingsEntry> createRatingsEntryDataFetcher() { return environment -> { long userId = util.getLongArg(environment, "userId", util.getDefaultUserId()); String className = util.getStringArg(environment, "className"); long classPK = util.getLongArg(environment, "classPK"); double score = util.getDoubleArg(environment, "score"); ServiceContext serviceContext = new ServiceContext(); return ratingsEntryLocalService.updateEntry( userId, className, classPK, score, serviceContext); }; }  @Reference(unbind = "-") void setRatingsEntryLocalService(RatingsEntryLocalService ratingsEntryLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<RatingsEntry>> getRatingsEntriesDataFetcher(); @Override DataFetcher<CompletableFuture<RatingsEntry>> getRatingsEntryDataFetcher(); @Override DataFetcher<RatingsEntry> createRatingsEntryDataFetcher(); @Override DataFetcher<RatingsEntry> deleteRatingsEntryDataFetcher();  }### Answer:
@Test public void createRatingsEntryDataFetcher_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("score", SCORE); DataFetchingEnvironment environment = getTestEnvironment(arguments); RatingsEntry expectedResult = mock(RatingsEntry.class); expectedResult.setUserId(USER_ID); expectedResult.setClassName(CLASS_NAME); expectedResult.setClassPK(CLASS_PK); expectedResult.setScore(SCORE); useMockGraphQLUtil(environment, USER_ID, true); when(localService.updateEntry(eq(USER_ID), eq(CLASS_NAME), eq(CLASS_PK), eq(SCORE), any(ServiceContext.class))) .thenReturn(expectedResult); RatingsEntry result = resolvers.createRatingsEntryDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void createRatingsEntryDataFetcher_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("score", SCORE); DataFetchingEnvironment environment = getTestEnvironment(arguments); RatingsEntry expectedResult = mock(RatingsEntry.class); expectedResult.setUserId(DEFAULT_USER_ID); expectedResult.setClassName(CLASS_NAME); expectedResult.setClassPK(CLASS_PK); expectedResult.setScore(SCORE); useMockGraphQLUtil(environment, DEFAULT_USER_ID, true); when(localService.updateEntry(eq(DEFAULT_USER_ID), eq(CLASS_NAME), eq(CLASS_PK), eq(SCORE), any(ServiceContext.class))) .thenReturn(expectedResult); RatingsEntry result = resolvers.createRatingsEntryDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = PortalException.class) public void createRatingsEntryDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, DEFAULT_USER_ID, false); when(localService.updateEntry(eq(DEFAULT_USER_ID), anyString(), anyLong(), anyDouble(), any(ServiceContext.class))) .thenThrow(PortalException.class); RatingsEntry result = resolvers.createRatingsEntryDataFetcher() .get(environment); assertNull(result); }