### Question:
TaskRestService extends RestServiceBase { @DELETE @Path("/task/{taskId}") @Produces(MediaType.APPLICATION_JSON) public Object cancelTask(@PathParam("taskId") @AuditId String id) { boolean ret = taskService.getTaskManager().cancelTask(id); return Response.ok(ret ? "Task canceled" : "Task not canceled").build(); }  @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 cancelTask() { TaskRestService tested = getTested(); TaskManager managerMock = mockTaskManager(tested); { Mockito.reset(managerMock); Mockito.when(managerMock.cancelTask("myid")).thenReturn(true); TestUtils.assertResponseStatus(tested.cancelTask("myid"), Status.OK, "Task canceled"); } { Mockito.reset(managerMock); Mockito.when(managerMock.cancelTask("myid")).thenReturn(false); TestUtils.assertResponseStatus(tested.cancelTask("myid"), Status.OK, "Task not canceled"); } }
@Test(expected = RuntimeException.class) public void cancelTask_errorFromService() { TaskRestService tested = getTested(); TaskManager managerMock = mockTaskManager(tested); Mockito.reset(managerMock); Mockito.when(managerMock.cancelTask("myid")).thenThrow(new RuntimeException("test exception")); TestUtils.assertResponseStatus(tested.cancelTask("myid"), Status.INTERNAL_SERVER_ERROR); }