### Question:
AlarmClockResource implements Resource { @GET @Path("alarms/{pathid}") @Produces(MediaType.APPLICATION_JSON) public Alarm getAlarm(@PathParam("pathid") int alarmnumber) { Alarm alarm; try { alarm = this.logic.getAlarm(alarmnumber); } catch (NoSuchElementException e) { throw new WebApplicationException("there is no alarm" + alarmnumber, e, Status.NOT_FOUND); } alarm.setLink(createAlarmPath(alarmnumber)); return alarm; }  @GET @Path("alarms") @Produces(MediaType.APPLICATION_JSON) List<Alarm> getAllAlarms(); @GET @Path("alarms/{pathid}") @Produces(MediaType.APPLICATION_JSON) Alarm getAlarm(@PathParam("pathid") int alarmnumber); @POST @Path("alarms/{pathid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Alarm editAlarm(@PathParam("pathid") int alarmNumber, Alarm alarmInc); @POST @Path("alarms/de.activate/{pathid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Alarm activatedeactivateAlarm(@PathParam("pathid") int alarmNumber, Alarm alarmInc); @POST @Path("alarms/delete/{pathid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Alarm deleteAlarm(@PathParam("pathid") int alarmNumber); @POST @Path("alarms/new") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Alarm newAlarm(Alarm alarm); @POST @Path("alarms/reset") void resetAlarms(); @Override ResourceEntity getPluginDescripion(); static final String PATH; }### Answer:
@Test void testGetAlarm() { List<Alarm> returnedAlarms = createAlarms(3, true); when(this.acl.getAlarm(2)).thenReturn(returnedAlarms.get(1)); when(this.acl.getAlarm(5)).thenThrow(new NoSuchElementException()); Response response = this.target.path("alarms/0").request().get(); assertThat(response, status(500)); response = this.target.path("alarms/2").request().get(); assertThat(response, status(200)); assertThat(this.acl.getAlarm(2).getId(), is(2)); response = this.target.path("alarms/5").request().get(); assertThat(response, status(404)); assertThat(response.readEntity(String.class), org.hamcrest.Matchers.startsWith("there is no alarm5")); }
@Test void testActivateAlarm() { List<Alarm> returnedAlarms = createAlarms(3, false); when(this.acl.getAlarm(1)).thenReturn(returnedAlarms.get(0)); Entity<Alarm> entity = Entity.entity(returnedAlarms.get(0), MediaType.APPLICATION_JSON); Response response = this.target.path("alarms/de.activate/1").request().post(entity); assertThat(response, status(204)); verify(this.acl).activateAlarm(1); }
@Test void testDeactivateAlarm() { List<Alarm> returnedAlarms = createAlarms(3, true); when(this.acl.getAlarm(1)).thenReturn(returnedAlarms.get(0)); Entity<Alarm> entity = Entity.entity(returnedAlarms.get(0), MediaType.APPLICATION_JSON); Response response = this.target.path("alarms/de.activate/1").request().post(entity); assertThat(response, status(204)); verify(this.acl).deactivateAlarm(1); }