### Question:
RoleResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Role createRole(Role role) { return roleService.createRole(role); } @Inject  RoleResource(RoleService roleService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<Role> listRoles(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Role createRole(Role role); @GET @Path("/{roleId}") @Produces(MediaType.APPLICATION_JSON) Role getRole(@PathParam("roleId") String roleId); @PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) Response updateRole(@PathParam("roleId") String roleId, Role role); @DELETE @Path("/{roleId}") Response deleteRole(@PathParam("roleId") String roleId);  }### Answer:
@Test public void createRole() { final Role requestRole = new Role(); requestRole.setId("role-1"); requestRole.setName("Role 1"); requestRole.setPermissions(Sets.newHashSet("test:create", "test:updated", "test:delete")); when(roleServiceMock.createRole(any(Role.class))).then(new Answer<Role>() { @Override public Role answer(InvocationOnMock invocation) { Role argRole = (Role) invocation.getArguments()[0]; assertEquals("Service role should equal the requested role", requestRole, argRole); return argRole; } }); Role responseRole = resource().path("/api/roles") .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .post(Role.class, requestRole); assertEquals("Response role should match the request role", requestRole, responseRole); verify(roleServiceMock).createRole(any(Role.class)); }