@Test public void listUsers() { User user1 = new User(); user1.setId("user-1"); user1.setUsername("user1"); user1.setFirstName("First Name 1"); user1.setLastName("Last Name 1"); user1.setEmail("user1@test.com"); User user2 = new User(); user2.setId("user-2"); user2.setUsername("user2"); user2.setFirstName("First Name 2"); user2.setLastName("Last Name 2"); user2.setEmail("user2@test.com"); List<User> mockedUsers = new ArrayList<User>(); mockedUsers.add(user1); mockedUsers.add(user2); when(userServiceMock.listUsers()).thenReturn(mockedUsers); List<User> responseUsers = resource().path("/api/users") .accept(MediaType.APPLICATION_JSON).get(new GenericType<List<User>>(){}); assertEquals("Response users should be equal to the mocked users", mockedUsers, responseUsers); verify(userServiceMock).listUsers(); }
@GET @Produces(MediaType.APPLICATION_JSON) public Collection<User> listUsers() { return userService.listUsers(); }
UserResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<User> listUsers() { return userService.listUsers(); } }
UserResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<User> listUsers() { return userService.listUsers(); } @Inject  UserResource(UserService userService); }
UserResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<User> listUsers() { return userService.listUsers(); } @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 { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<User> listUsers() { return userService.listUsers(); } @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);  }