### Question:
RatingRestService extends RestServiceBase { @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public Object getRating(@PathParam(QUERY_PARAM_ID) String contentSysId) { checkIfUserAuthenticated(); contentSysId = SearchUtils.trimToNull(contentSysId); if (contentSysId == null) { throw new RequiredFieldException(QUERY_PARAM_ID); } String currentContributorId = authenticationUtilService.getAuthenticatedContributor(false); if (currentContributorId != null) { List<Rating> rl = ratingPersistenceService.getRatings(currentContributorId, contentSysId); if (rl != null && !rl.isEmpty()) { Map<String, Object> ret = ratingToJSON(rl.get(0)); return ret; } else { return Response.status(Status.NOT_FOUND).build(); } } else { return Response.status(Status.NOT_FOUND).build(); } }  @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) Object getRating(@PathParam(QUERY_PARAM_ID) String contentSysId); @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) Map<String, Object> getRatings(@Context UriInfo uriInfo); @POST @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Object postRating(@PathParam(QUERY_PARAM_ID) String contentSysId, Map<String, Object> requestContent); static final String QUERY_PARAM_ID; static final String DATA_FIELD_RATING; }### Answer:
@Test(expected = RequiredFieldException.class) public void getRating_invalidParam_1() { RatingRestService tested = getTested(); tested.getRating(null); }
@Test(expected = RequiredFieldException.class) public void getRating_invalidParam_2() { RatingRestService tested = getTested(); tested.getRating(" "); }
@Test public void getRating() { RatingRestService tested = getTested(); { Mockito.when( tested.ratingPersistenceService.getRatings(Mockito.eq(MOCK_CONTRIB_ID), Mockito.eq(MOCK_CONTENT_ID_1))) .thenReturn(null); TestUtils.assertResponseStatus(tested.getRating(MOCK_CONTENT_ID_1), Status.NOT_FOUND); Mockito.verify(tested.ratingPersistenceService).getRatings(Mockito.eq(MOCK_CONTRIB_ID), Mockito.eq(MOCK_CONTENT_ID_1)); } { Mockito.reset(tested.ratingPersistenceService); Mockito.when( tested.ratingPersistenceService.getRatings(Mockito.eq(MOCK_CONTRIB_ID), Mockito.eq(MOCK_CONTENT_ID_1))) .thenReturn(new ArrayList<Rating>()); TestUtils.assertResponseStatus(tested.getRating(MOCK_CONTENT_ID_1), Status.NOT_FOUND); Mockito.verify(tested.ratingPersistenceService).getRatings(Mockito.eq(MOCK_CONTRIB_ID), Mockito.eq(MOCK_CONTENT_ID_1)); } { List<Rating> ret = new ArrayList<Rating>(); ret.add(new Rating(MOCK_CONTENT_ID_1, MOCK_CONTRIB_ID, 3, null)); Mockito.reset(tested.ratingPersistenceService); Mockito.when( tested.ratingPersistenceService.getRatings(Mockito.eq(MOCK_CONTRIB_ID), Mockito.eq(MOCK_CONTENT_ID_1))) .thenReturn(ret); @SuppressWarnings("unchecked") Map<String, Object> aret = (Map<String, Object>) tested.getRating(MOCK_CONTENT_ID_1); assertRatingJSON(aret, 3); } }