### Question:
TaskRestService extends RestServiceBase { @GET @Path("/task") @Produces(MediaType.APPLICATION_JSON) @AuditIgnore public Object getTasks(@QueryParam("taskType") String taskType, @QueryParam("taskStatus") String[] taskStatus, @QueryParam("from") Integer from, @QueryParam("size") Integer size) { List<TaskStatus> taskStatusFilter = null; if (taskStatus != null && taskStatus.length > 0) { taskStatusFilter = new ArrayList<TaskStatus>(); for (String s : taskStatus) { TaskStatus ts = TaskStatus.fromString(s); if (ts != null) taskStatusFilter.add(ts); } } return taskService.getTaskManager().listTasks(taskType, taskStatusFilter, from != null ? from : 0, size != null ? size : 0); }  @GET @Path("/type") @Produces(MediaType.APPLICATION_JSON) @AuditIgnore Object getTypes(); @GET @Path("/task") @Produces(MediaType.APPLICATION_JSON) @AuditIgnore Object getTasks(@QueryParam("taskType") String taskType, @QueryParam("taskStatus") String[] taskStatus,
						   @QueryParam("from") Integer from, @QueryParam("size") Integer size); @GET @Path("/task/{taskId}") @Produces(MediaType.APPLICATION_JSON) @AuditIgnore Object getTask(@PathParam("taskId") String taskId); @POST @Path("/task/{taskType}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Object createTask(@PathParam("taskType") @AuditId String taskType, @AuditContent Map<String, Object> content); @DELETE @Path("/task/{taskId}") @Produces(MediaType.APPLICATION_JSON) Object cancelTask(@PathParam("taskId") @AuditId String id);  }### Answer:
@Test public void getTasks() { TaskRestService tested = getTested(); TaskManager managerMock = mockTaskManager(tested); { List<TaskStatusInfo> value = new ArrayList<TaskStatusInfo>(); Mockito.when(managerMock.listTasks(null, null, 0, 0)).thenReturn(value); Assert.assertEquals(value, tested.getTasks(null, null, null, null)); Mockito.verify(managerMock).listTasks(null, null, 0, 0); } { Mockito.reset(managerMock); List<TaskStatusInfo> value = new ArrayList<TaskStatusInfo>(); String[] ts = new String[] { TaskStatus.FAILOVER.toString() }; List<TaskStatus> tslist = new ArrayList<TaskStatus>(); tslist.add(TaskStatus.FAILOVER); Mockito.when(managerMock.listTasks("aa", tslist, 10, 5)).thenReturn(value); Assert.assertEquals(value, tested.getTasks("aa", ts, 10, 5)); Mockito.verify(managerMock).listTasks("aa", tslist, 10, 5); } }
@Test(expected = RuntimeException.class) public void getTasks_errorFromSerice() { TaskRestService tested = getTested(); TaskManager managerMock = mockTaskManager(tested); Mockito.reset(managerMock); Mockito.when(managerMock.listTasks(null, null, 0, 0)).thenThrow(new RuntimeException("test exception")); TestUtils.assertResponseStatus(tested.getTasks(null, null, 0, 0), Status.INTERNAL_SERVER_ERROR); }