### Question:
TimerEventTriggerResource extends CommonResource { @Get("json") public void searchTimerEventTriggers() { try { final Long caseId = getLongParameter("caseId", true); final SearchResult<TimerEventTriggerInstance> searchResult = processAPI.searchTimerEventTriggerInstances(caseId, buildSearchOptions()); Representation representation = getConverterService().toRepresentation(searchResult.getResult(), MediaType.APPLICATION_JSON); representation.setCharacterSet(CharacterSet.UTF_8); getResponse().setEntity(representation); setContentRange(searchResult); } catch (final Exception e) { throw new APIException(e); } } TimerEventTriggerResource(final ProcessAPI processAPI); @Get("json") void searchTimerEventTriggers(); @Put("json") TimerEventTrigger updateTimerEventTrigger(final TimerEventTrigger trigger); @Override String getAttribute(final String attributeName); static final String ID_PARAM_NAME; }### Answer:
@Test public void searchTimerEventTriggersShouldCallEngine() throws Exception { final SearchOptions searchOptions = mock(SearchOptions.class); doReturn(1L).when(restResource).getLongParameter(anyString(), anyBoolean()); doReturn(1).when(restResource).getIntegerParameter(anyString(), anyBoolean()); Response mockResponse = mock(Response.class); doReturn(mockResponse).when(restResource).getResponse(); doReturn(mock(Representation.class)).when(mockResponse).getEntity(); doReturn(searchOptions).when(restResource).buildSearchOptions(); SearchResult<TimerEventTriggerInstance> searchResult = mock(SearchResult.class); doReturn(Collections.emptyList()).when(searchResult).getResult(); doReturn(1L).when(searchResult).getCount(); doReturn(searchResult).when(processAPI).searchTimerEventTriggerInstances(anyLong(), eq(searchOptions)); restResource.searchTimerEventTriggers(); verify(processAPI).searchTimerEventTriggerInstances(1L, searchOptions); }
@Test(expected = APIException.class) public void searchTimerEventTriggersShouldThrowExceptionIfParameterNotFound() throws Exception { doReturn(null).when(restResource).getParameter(anyString(), anyBoolean()); restResource.searchTimerEventTriggers(); }