### Question:
ProviderRestService extends RestEntityServiceBase { @POST @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Object create(@AuditContent Map<String, Object> data) { String nameFromData = (String) data.get(ProviderService.NAME); if (StringUtils.isBlank(nameFromData)) return Response.status(Status.BAD_REQUEST).entity("Required data field '" + ProviderService.NAME + "' not set") .build(); return this.create(nameFromData, data); }  @PostConstruct void init(); @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) @AuditIgnore Object getAll(@QueryParam("from") Integer from, @QueryParam("size") Integer size); @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({ Role.ADMIN, Role.PROVIDER }) @Override @AuditIgnore Object get(@PathParam("id") String id); @POST @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Object create(@AuditContent Map<String, Object> data); @POST @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Object create(@PathParam("id") @AuditId String id, @AuditContent Map<String, Object> data); @POST @Path("/{id}/password") @RolesAllowed({ Role.ADMIN, Role.PROVIDER }) Object changePassword(@PathParam("id") @AuditId String id, String pwd); @POST @Path("/{id}/content_manipulation_lock") @RolesAllowed({ Role.ADMIN, Role.PROVIDER }) Object contentManipulationLockCreate(@PathParam("id") @AuditId String id); @DELETE @Path("/{id}/content_manipulation_lock") @RolesAllowed({ Role.ADMIN, Role.PROVIDER }) Object contentManipulationLockDelete(@PathParam("id") @AuditId String id); @GET @Path("/{id}/content_manipulation_lock") @RolesAllowed({ Role.ADMIN, Role.PROVIDER }) @Produces(MediaType.APPLICATION_JSON) Map<String, Object> contentManipulationLockInfo(@PathParam("id") @AuditId String id);  }### Answer:
@Test(expected = RequiredFieldException.class) public void create_id_inputParamValidation() { ProviderRestService tested = getTested(); Map<String, Object> m = new HashMap<String, Object>(); m.put(ProviderService.NAME, "myname"); TestUtils.assertResponseStatus(tested.create(null, m), Status.BAD_REQUEST); TestUtils.assertResponseStatus(tested.create("", m), Status.BAD_REQUEST); }
@Test(expected = RuntimeException.class) public void create_id_errorFromService() { ProviderRestService tested = getTested(); Mockito.reset(tested.providerService); Map<String, Object> m = new HashMap<String, Object>(); m.put(ProviderService.NAME, "myname"); Mockito.doThrow(new RuntimeException("my exception")).when(tested.providerService).create("myname", m); tested.create("myname", m); }
@Test(expected = RuntimeException.class) public void create_noid_exceptionFromService() { ProviderRestService tested = getTested(); Mockito.reset(tested.providerService); Map<String, Object> m = new HashMap<String, Object>(); m.put(ProviderService.NAME, "myname"); Mockito.doThrow(new RuntimeException("my exception")).when(tested.providerService).create("myname", m); tested.create(m); }