### Question:
TimerResource implements Resource { @GET @Path("timers/{pathid}") @Produces(MediaType.APPLICATION_JSON) public Timer getTimer(@PathParam("pathid") int timerNumber) { Timer timer; try { timer = this.logic.getTimer(timerNumber); } catch (NoSuchElementException e) { throw new WebApplicationException("there is no timer" + timerNumber, e, Status.NOT_FOUND); } timer.setLink(createTimerPath(timerNumber)); return timer; }  @GET @Path("timers") @Produces(MediaType.APPLICATION_JSON) List<Timer> getAllTimers(); @GET @Path("timers/{pathid}") @Produces(MediaType.APPLICATION_JSON) Timer getTimer(@PathParam("pathid") int timerNumber); @POST @Path("timers/new") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Timer newTimer(Timer timer); @POST @Path("timers/deleteAll") void deleteAllTimers(); @POST @Path("timers/delete/{pathid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Timer deleteTimer(@PathParam("pathid") int timerNumber); @POST @Path("timers/de.activate/{pathid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Timer activatedeactivateAlarm(@PathParam("pathid") int timerNumber, Timer timerInc); @Override ResourceEntity getPluginDescripion(); static final String PATH; }### Answer:
@Test void testGetTimer() { List<Timer> returnedTimers = createTimers(3, true); when(this.tLogic.getTimer(2)).thenReturn(returnedTimers.get(1)); when(this.tLogic.getTimer(5)).thenThrow(new NoSuchElementException()); Response response = this.target.path("timers/0").request().get(); assertThat(response, status(500)); response = this.target.path("timers/2").request().get(); assertThat(response, status(200)); assertThat(this.tLogic.getTimer(2).getId(), is(2)); response = this.target.path("timers/5").request().get(); assertThat(response, status(404)); assertThat(response.readEntity(String.class), org.hamcrest.Matchers.startsWith("there is no timer5")); }
@Test void testReactivateTimer() { List<Timer> returnedTimers = createTimers(3, false); when(this.tLogic.getTimer(1)).thenReturn(returnedTimers.get(0)); Entity<Timer> entity = Entity.entity(returnedTimers.get(0), MediaType.APPLICATION_JSON); Response response = this.target.path("timers/de.activate/1").request().post(entity); assertThat(response, status(204)); verify(this.tLogic).reactivateTimer(any()); }
@Test void testPauseTimer() { List<Timer> returnedTimers = createTimers(3, true); when(this.tLogic.getTimer(1)).thenReturn(returnedTimers.get(0)); Entity<Timer> entity = Entity.entity(returnedTimers.get(0), MediaType.APPLICATION_JSON); Response response = this.target.path("timers/de.activate/1").request().post(entity); assertThat(response, status(204)); verify(this.tLogic).pauseTimer(any()); }