### Question:
SearchRestService extends RestServiceBase { protected Object writeSearchHitUsedStatisticsRecord(@PathParam("search_result_uuid") String uuid, @PathParam("hit_id") String contentId, @QueryParam("session_id") String sessionId) { if ((uuid = SearchUtils.trimToNull(uuid)) == null) { throw new RequiredFieldException("search_result_uuid"); } if ((contentId = SearchUtils.trimToNull(contentId)) == null) { throw new RequiredFieldException("hit_id"); } sessionId = SearchUtils.trimToNull(sessionId); boolean result = searchService.writeSearchHitUsedStatisticsRecord(uuid, contentId, sessionId); return Response.ok(result ? "statistics record accepted" : "statistics record ignored").build(); }  @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) @PermitAll Object search(@Context UriInfo uriInfo); @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) @PermitAll Object searchRegisteredQuery(@PathParam("id") @AuditId String id, @Context UriInfo uriInfo); @PUT @Path("/{search_result_uuid}/{hit_id}") @PermitAll Object writeSearchHitUsedStatisticsRecordPUT(@PathParam("search_result_uuid") String uuid,
			@PathParam("hit_id") String contentId, @QueryParam("session_id") String sessionId); @POST @Path("/{search_result_uuid}/{hit_id}") @PermitAll Object writeSearchHitUsedStatisticsRecordPOST(@PathParam("search_result_uuid") String uuid,
			@PathParam("hit_id") String contentId, @QueryParam("session_id") String sessionId);  }### Answer:
@Test(expected = RequiredFieldException.class) public void writeSearchHitUsedStatisticsRecord_invalidParam_1() { SearchRestService tested = getTested(); tested.writeSearchHitUsedStatisticsRecord(null, "aa", null); }
@Test public void writeSearchHitUsedStatisticsRecord() { SearchRestService tested = getTested(); { Mockito.reset(tested.searchService); Mockito.when(tested.searchService.writeSearchHitUsedStatisticsRecord("aaa", "bb", null)).thenReturn(true); TestUtils.assertResponseStatus(tested.writeSearchHitUsedStatisticsRecord(" aaa ", " bb ", " "), Status.OK); Mockito.verify(tested.searchService).writeSearchHitUsedStatisticsRecord("aaa", "bb", null); Mockito.verifyNoMoreInteractions(tested.searchService); } { Mockito.reset(tested.searchService); Mockito.when(tested.searchService.writeSearchHitUsedStatisticsRecord("aaa", "bb", null)).thenReturn(true); TestUtils.assertResponseStatus(tested.writeSearchHitUsedStatisticsRecord("aaa", "bb", null), Status.OK, "statistics record accepted"); Mockito.verify(tested.searchService).writeSearchHitUsedStatisticsRecord("aaa", "bb", null); Mockito.verifyNoMoreInteractions(tested.searchService); } { Mockito.reset(tested.searchService); Mockito.when(tested.searchService.writeSearchHitUsedStatisticsRecord("aaa", "bb", "jj")).thenReturn(false); TestUtils.assertResponseStatus(tested.writeSearchHitUsedStatisticsRecord("aaa", "bb", "jj"), Status.OK, "statistics record ignored"); Mockito.verify(tested.searchService).writeSearchHitUsedStatisticsRecord("aaa", "bb", "jj"); Mockito.verifyNoMoreInteractions(tested.searchService); } }
@Test(expected = RuntimeException.class) public void writeSearchHitUsedStatisticsRecord_exceptionFromService() { SearchRestService tested = getTested(); Mockito.reset(tested.searchService); Mockito.when(tested.searchService.writeSearchHitUsedStatisticsRecord("aaa", "bb", null)).thenThrow( new RuntimeException("exception")); tested.writeSearchHitUsedStatisticsRecord("aaa", "bb", null); }