### Question:
DimlevelService { @GET @Path("/{id}") public Response getDimlevel(@PathParam("id") String id) { Response response = null; UUID uuid = null; Dimmer dimmer = null; logRequest("", id); response = ElisResponseBuilder.buildBadRequestResponse(); try { uuid = UUID.fromString(id); } catch (Exception e) { log(LogService.LOG_WARNING, "Bad UUID"); } if (userService != null && storage != null && uuid != null) { if (storage.objectExists(uuid)) { try { dimmer = (Dimmer) storage.readData(uuid); DimlevelBean bean = new DimlevelBean(); bean.device = uuid; bean.dimlevel = (int) (100 * dimmer.getDimLevel()); response = ElisResponseBuilder.buildOKResponse(bean); } catch (StorageException | ClassCastException e) { log(LogService.LOG_INFO, "Tried to perform a getPowerstate on a non-power switch object: " + uuid); response = ElisResponseBuilder.buildMethodNotAllowedResponse(); } catch (ActuatorFailedException e) { log(LogService.LOG_WARNING, "Couldn't read device status from: " + uuid); response = ElisResponseBuilder.buildServiceUnavailableResponse(); } } else { response = ElisResponseBuilder.buildNotFoundResponse(); } } return response; } DimlevelService();  DimlevelService(UserService us, Storage storage, EndpointUtils utils); @GET @Path("/{id}") Response getDimlevel(@PathParam("id") String id); @PUT @Path("/{id}") Response setDimlevel(@PathParam("id") String id,
			DimlevelBean bean);  }### Answer:
@Test public void testSetDimlevelValueIsZero() { try { when(device.getDimLevel()).thenReturn((float) 0); } catch (ActuatorFailedException e) {} final Entity<String> requestBody = Entity.entity("{\"dimlevel\": 0}", MediaType.APPLICATION_JSON_TYPE); final String response = target("/dimlevel/" + DID + "/").request(MediaType.APPLICATION_JSON_TYPE).put(requestBody, String.class); EnvelopeBean envelope = gson.fromJson(response, EnvelopeBean.class); DimlevelBean bean = gson.fromJson(gson.toJson(envelope.response), DimlevelBean.class); assertEquals(DID, bean.device); assertEquals(0, bean.dimlevel); }
@Test public void testSetDimlevelValueIs100() { try { when(device.getDimLevel()).thenReturn((float) 1); } catch (ActuatorFailedException e) {} final Entity<String> requestBody = Entity.entity("{\"dimlevel\": 100}", MediaType.APPLICATION_JSON_TYPE); final String response = target("/dimlevel/" + DID + "/").request(MediaType.APPLICATION_JSON_TYPE).put(requestBody, String.class); EnvelopeBean envelope = gson.fromJson(response, EnvelopeBean.class); DimlevelBean bean = gson.fromJson(gson.toJson(envelope.response), DimlevelBean.class); assertEquals(DID, bean.device); assertEquals(100, bean.dimlevel); }
@Test public void testGetDimlevel() { final String deviceResponse = target("/dimlevel/" + DID + "/").request().get(String.class); EnvelopeBean envelope = gson.fromJson(deviceResponse, EnvelopeBean.class); DimlevelBean bean = gson.fromJson(gson.toJson(envelope.response), DimlevelBean.class); assertEquals(DID, bean.device); assertEquals(DIMLEVEL, bean.dimlevel); }