### Question:
ContributorRestService extends RestEntityServiceBase { @POST @Path("/{idFrom}/mergeTo/{idTo}") @Produces(MediaType.APPLICATION_JSON) public Object mergeContributors(@PathParam("idFrom") @AuditId String idFrom, @AuditContent @PathParam("idTo") String idTo) throws ObjectNotFoundException { if ((idFrom = SearchUtils.trimToNull(idFrom)) == null) { throw new RequiredFieldException("idFrom"); } if ((idTo = SearchUtils.trimToNull(idTo)) == null) { throw new RequiredFieldException("id"); } return contributorService.mergeContributors(idFrom, idTo); }  @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 mergeContributors_validation_idTo2() throws Exception { getTested().mergeContributors("idfrom", " "); }
@Test public void mergeContributors() throws Exception { ContributorRestService tested = getTested(); Map<String, Object> value = new HashMap<String, Object>(); Mockito.when(tested.contributorService.mergeContributors("from", "to")).thenReturn(value); Assert.assertEquals(value, tested.mergeContributors("idFrom", "idTo")); }
@Test(expected = ObjectNotFoundException.class) public void mergeContributors_exception() throws Exception { ContributorRestService tested = getTested(); Mockito.when(tested.contributorService.mergeContributors(Mockito.anyString(), Mockito.anyString())).thenThrow( new ObjectNotFoundException()); tested.mergeContributors("id", "id2"); }
@Test(expected = RequiredFieldException.class) public void mergeContributors_validation_idFrom() throws Exception { getTested().mergeContributors(null, "idto"); }
@Test(expected = RequiredFieldException.class) public void mergeContributors_validation_idFrom2() throws Exception { getTested().mergeContributors(" ", "idto"); }
@Test(expected = RequiredFieldException.class) public void mergeContributors_validation_idTo() throws Exception { getTested().mergeContributors("idfrom", null); }