SessionResource { @POST @Path("/login") public AccessToken login(LoginCredentials credentials) { User user = userDAO.getUserByEmail(credentials.getEmail()); if (user == null) { throw new UnauthorizedException(); } if(failedLoginDAO.attemptsInLastFiveMinutes(user.getId()) >= 5){ failedLoginDAO.addAttempt(user.getId()); throw new UnauthorizedException(); } try { if (user.checkPassword(credentials.getPassword())) { return accessTokenDAO.generateToken(user.getId()); } else { failedLoginDAO.addAttempt(user.getId()); throw new UnauthorizedException(); } } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { failedLoginDAO.addAttempt(user.getId()); throw new UnauthorizedException(); } } SessionResource(AccessTokenDAO accessTokenDAO, UserDAO userDAO, FailedLoginDAO failedLoginDAO, FacebookClient client, AmazonClient s3); @POST @Path("/login") AccessToken login(LoginCredentials credentials); @POST @Path("/logout") void logout(@Auth AccessToken token); @GET @Path("/currentUser") User currentUser(@Auth AccessToken token); @POST @Path("/fbLogin") AccessToken fbLogin(String fbToken);  }
@Test public void testLogin() throws Exception { Response res = rule.getJerseyTest() .target("/session/login") .request().accept(MediaType.APPLICATION_JSON) .post(Entity.json(creds)); assertThat(res.getStatusInfo().getStatusCode()).isBetween(200, 300); verify(userDao).getUserByEmail(any()); verify(failedLoginDao).attemptsInLastFiveMinutes(any()); }