@Test public void updateUser() { final User requestUser = new User(); requestUser.setId("user-1"); requestUser.setUsername("user1"); requestUser.setFirstName("First Name"); requestUser.setLastName("Last Name"); requestUser.setEmail("user1@test.com"); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { String argUserId = (String) invocation.getArguments()[0]; User argUser = (User) invocation.getArguments()[1]; assertEquals("Service user ID should match the requested user ID", argUserId, requestUser.getId()); assertEquals("Service user should match the requested user", argUser, requestUser); return null; } }).when(userServiceMock).updateUser(anyString(), any(User.class)); ClientResponse clientResponse = resource().path("/api/users/" + requestUser.getId()) .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .put(ClientResponse.class, requestUser); assertEquals("Response HTTP status code should be 200 (OK)", clientResponse.getStatus(), 200); verify(userServiceMock).updateUser(anyString(), any(User.class)); }
@PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateUser(@PathParam("userId") String userId, User user) { userService.updateUser(userId, user); return Response.ok().build(); }
UserResource { @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateUser(@PathParam("userId") String userId, User user) { userService.updateUser(userId, user); return Response.ok().build(); } }
UserResource { @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateUser(@PathParam("userId") String userId, User user) { userService.updateUser(userId, user); return Response.ok().build(); } @Inject  UserResource(UserService userService); }
UserResource { @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateUser(@PathParam("userId") String userId, User user) { userService.updateUser(userId, user); return Response.ok().build(); } @Inject  UserResource(UserService userService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<User> listUsers(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) User createUser(User user); @GET @Path("/{userId}") @Produces(MediaType.APPLICATION_JSON) User getUser(@PathParam("userId") String userId); @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) Response updateUser(@PathParam("userId") String userId, User user); @DELETE @Path("/{userId}") Response deleteUser(@PathParam("userId") String userId); @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) Response updateUserPassword(@PathParam("userId") String userId,
            PasswordChange passwordChange); }
UserResource { @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateUser(@PathParam("userId") String userId, User user) { userService.updateUser(userId, user); return Response.ok().build(); } @Inject  UserResource(UserService userService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<User> listUsers(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) User createUser(User user); @GET @Path("/{userId}") @Produces(MediaType.APPLICATION_JSON) User getUser(@PathParam("userId") String userId); @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) Response updateUser(@PathParam("userId") String userId, User user); @DELETE @Path("/{userId}") Response deleteUser(@PathParam("userId") String userId); @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) Response updateUserPassword(@PathParam("userId") String userId,
            PasswordChange passwordChange);  }