TaskResource { @Operation(summary = "Get single task by id", description = "Get single task by id") @GET @Path("{id}") public Response getTask(@PathParam("id") Integer id) { Task task = taskService.getById(id); return task == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(task).build(); } TaskResource(TaskService taskService, MetricRegistry metricRegistry); @Operation(summary = "Get single task by id", description = "Get single task by id") @GET @Path("{id}") Response getTask(@PathParam("id") Integer id); @Operation(description = "Add task") @POST Response addTask(Task task); @Operation(description = "Get all tasks") @GET @Produces(MediaType.APPLICATION_JSON) Collection<Task> getTasks(); @Operation(description = "Change task") @PUT @Path("{id}") void updateTask(@PathParam("id") Integer id, Task task); @Operation(description = "Delete task") @DELETE @Path("{id}") void deleteTask(@PathParam("id") Integer id);  }
@Test public void testGet() { when(taskService.getById(1)).thenReturn(task1); Response resp = taskRes.getTask(1); assertThat(resp.getStatus(), equalTo(200)); assertThat(resp.getEntity(), equalTo(task1)); }
@Test public void testGetNotFound() { Response resp = taskRes.getTask(1); assertThat(resp.getStatus(), equalTo(404)); }