UserService extends BasicService { @GET @Path("/users/{userId}") @Produces(MediaType.APPLICATION_JSON) public User getUser(@PathParam("userId") long userId) { return getExistingUser(userId); }  @GET @Path("/user") @Produces(MediaType.APPLICATION_JSON) User getCurrentUser(); @GET @Path("/users/{userId}") @Produces(MediaType.APPLICATION_JSON) User getUser(@PathParam("userId") long userId); @DELETE @Path("/users/{userId}") Response deleteUser(@PathParam("userId") long userId); @POST @Path("/users/{userId}/impersonate") Response impersonateUser(@PathParam("userId") long userId); @POST @Path("/stopimpersonation") Response stopImpersonation(); @POST @Path("/logout") Response logoutCurrentUser();  }
@Test(expected = WebApplicationException.class) public void testGetNonExistingUser() throws Exception { doReturn(true).when(userService).isAdmin(); userService.getUser(-1); }
@Test public void testGetOtherUserAsAdmin() throws Exception { doReturn(true).when(userService).isAdmin(); simpleUser2 = UserUtil.getInstance().getDBUser(simpleUser2.getUserId()); assertEquals(simpleUser2.getUserId(), userService.getUser(simpleUser2.getId()).getUserId()); }
@Test public void testGetUser() throws Exception { simpleUser = UserUtil.getInstance().getDBUser(simpleUser.getUserId()); User user = userService.getUser(simpleUser.getId()); assertNotNull(user); assertEquals(simpleUser.getUserId(), user.getUserId()); }