@Test public void createUser() { 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"); when(userServiceMock.createUser(any(User.class))).then(new Answer<User>() { @Override public User answer(InvocationOnMock invocation) { User argUser = (User) invocation.getArguments()[0]; assertEquals("Service user should equal the requested user", requestUser, argUser); return argUser; } }); User responseUser = resource().path("/api/users") .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .post(User.class, requestUser); assertEquals("Response user should match the request user", requestUser, responseUser); verify(userServiceMock).createUser(any(User.class)); }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public User createUser(User user) { return userService.createUser(user); }
UserResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public User createUser(User user) { return userService.createUser(user); } }
UserResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public User createUser(User user) { return userService.createUser(user); } @Inject  UserResource(UserService userService); }
UserResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public User createUser(User user) { return userService.createUser(user); } @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 { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public User createUser(User user) { return userService.createUser(user); } @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);  }