### Question:
TaskRestService extends RestServiceBase { @POST @Path("/task/{taskType}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Object createTask(@PathParam("taskType") @AuditId String taskType, @AuditContent Map<String, Object> content) { try { String id = taskService.getTaskManager().createTask(taskType, content); return createResponseWithId(id); } catch (TaskConfigurationException e) { return Response.status(Status.BAD_REQUEST) .entity("Configuration is invalid for used taskType: " + e.getMessage()).build(); } catch (UnsupportedTaskException e) { return Response.status(Status.BAD_REQUEST).entity("Used taskType is not supported").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:
@SuppressWarnings("unchecked") @Test public void createTask() throws UnsupportedTaskException, TaskConfigurationException { TaskRestService tested = getTested(); TaskManager managerMock = mockTaskManager(tested); { String value = "idsd"; Map<String, Object> cfg = new HashMap<String, Object>(); Mockito.when(managerMock.createTask("mytype", cfg)).thenReturn(value); Map<String, Object> result = (Map<String, Object>) tested.createTask("mytype", cfg); Assert.assertNotNull(result); Assert.assertEquals(value, result.get("id")); Mockito.verify(managerMock).createTask("mytype", cfg); } { Mockito.reset(managerMock); Mockito.when(managerMock.createTask("mytype", null)).thenThrow(new UnsupportedTaskException("test exception")); TestUtils.assertResponseStatus(tested.createTask("mytype", null), Status.BAD_REQUEST); } { Mockito.reset(managerMock); Mockito.when(managerMock.createTask("mytype", null)).thenThrow(new TaskConfigurationException("test exception")); TestUtils.assertResponseStatus(tested.createTask("mytype", null), Status.BAD_REQUEST); } }
@Test(expected = RuntimeException.class) public void createTask_errorFromSerice() throws UnsupportedTaskException, TaskConfigurationException { TaskRestService tested = getTested(); TaskManager managerMock = mockTaskManager(tested); Mockito.reset(managerMock); Mockito.when(managerMock.createTask("mytype", null)).thenThrow(new RuntimeException("test exception")); TestUtils.assertResponseStatus(tested.createTask("mytype", null), Status.INTERNAL_SERVER_ERROR); }