### Question:
ProjectRestService extends RestEntityServiceBase { @POST @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Object create(@AuditContent Map<String, Object> data) { String codeFromData = (String) data.get(ProjectService.FIELD_CODE); if (codeFromData == null || codeFromData.isEmpty()) return Response.status(Status.BAD_REQUEST) .entity("Required data field '" + ProjectService.FIELD_CODE + "' not set").build(); return this.create(codeFromData, data); }  @PostConstruct void init(); @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) @Override @PermitAll @AuditIgnore Object getAll(@QueryParam("from") Integer from, @QueryParam("size") Integer size); @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) @Override @PermitAll @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); @GET @Path("/search") @Produces(MediaType.APPLICATION_JSON) @AuditIgnore Object search(@Context UriInfo uriInfo); static final String PARAM_CODE; }### Answer:
@Test(expected = RequiredFieldException.class) public void create_id_invalidParam() { ProjectRestService tested = getTested(); { Map<String, Object> m = new HashMap<String, Object>(); m.put(ProjectService.FIELD_CODE, "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() { ProjectRestService tested = getTested(); Mockito.reset(tested.entityService); Map<String, Object> m = new HashMap<String, Object>(); m.put(ProjectService.FIELD_CODE, "myname"); Mockito.doThrow(new RuntimeException("my exception")).when(tested.entityService).create("myname", m); tested.create("myname", m); }
@Test(expected = RuntimeException.class) public void create_noid_errorFromService() { ProjectRestService tested = getTested(); Mockito.reset(tested.entityService); Map<String, Object> m = new HashMap<String, Object>(); m.put(ProjectService.FIELD_CODE, "myname"); Mockito.doThrow(new RuntimeException("my exception")).when(tested.entityService).create("myname", m); tested.create(m); }