### Question:
RoleResource { @GET @Path("/{roleId}") @Produces(MediaType.APPLICATION_JSON) public Role getRole(@PathParam("roleId") String roleId) { return roleService.getRole(roleId); } @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 getRole() { final Role mockedRole = new Role(); mockedRole.setId("role-1"); mockedRole.setName("Role 1"); mockedRole.setPermissions(Sets.newHashSet("test:create", "test:updated", "test:delete")); when(roleServiceMock.getRole(anyString())).then(new Answer<Role>() { @Override public Role answer(InvocationOnMock invocation) throws Throwable { String argRoleId = (String) invocation.getArguments()[0]; assertEquals("Service role ID should match the requested role ID", argRoleId, mockedRole.getId()); return mockedRole; } }); Role responseRole = resource().path("/api/roles/" + mockedRole.getId()) .accept(MediaType.APPLICATION_JSON).get(Role.class); assertEquals("Response role should match the mocked role", mockedRole, responseRole); verify(roleServiceMock).getRole(anyString()); }