### Question:
ContributorRestService extends RestEntityServiceBase { @POST @Path("/{id}/code/{code}") @Produces(MediaType.APPLICATION_JSON) public Object codeChange(@PathParam("id") @AuditId String id, @AuditContent @PathParam("code") String code) throws ObjectNotFoundException { if ((id = SearchUtils.trimToNull(id)) == null) { throw new RequiredFieldException("id"); } if ((code = SearchUtils.trimToNull(code)) == null) { throw new RequiredFieldException("code"); } return contributorService.changeContributorCode(id, code); }  @PostConstruct void init(); @GET @Path("/search") @Produces(MediaType.APPLICATION_JSON) @AuditIgnore Object search(@Context UriInfo uriInfo); @POST @Path("/{id}/code/{code}") @Produces(MediaType.APPLICATION_JSON) Object codeChange(@PathParam("id") @AuditId String id, @AuditContent @PathParam("code") String code); @POST @Path("/{idFrom}/mergeTo/{idTo}") @Produces(MediaType.APPLICATION_JSON) Object mergeContributors(@PathParam("idFrom") @AuditId String idFrom, @AuditContent @PathParam("idTo") String idTo); static final String PARAM_EMAIL; static final String PARAM_CODE; static final String PARAM_NAME; }### Answer:
@Test(expected = RequiredFieldException.class) public void codeChange_validation_id() throws Exception { getTested().codeChange(null, "code"); }
@Test(expected = RequiredFieldException.class) public void codeChange_validation_id2() throws Exception { getTested().codeChange(" ", "code"); }
@Test(expected = RequiredFieldException.class) public void codeChange_validation_code() throws Exception { getTested().codeChange("id", null); }
@Test(expected = RequiredFieldException.class) public void codeChange_validation_code2() throws Exception { getTested().codeChange("id", " "); }
@Test public void codeChange() throws Exception { ContributorRestService tested = getTested(); Map<String, Object> value = new HashMap<String, Object>(); Mockito.when(tested.contributorService.changeContributorCode("id", "code")).thenReturn(value); Assert.assertEquals(value, tested.codeChange("id", "code")); }
@Test(expected = BadRequestException.class) public void codeChange_exception() throws Exception { ContributorRestService tested = getTested(); Mockito.doThrow(new BadRequestException("a")).when(tested.contributorService) .changeContributorCode(Mockito.anyString(), Mockito.anyString()); tested.codeChange("id", "code"); }