@Test(expected = BadCredentialsException.class) public void shouldThrowExceptionIfUserIsNotFound() { String username = "******"; String password = "******"; when(allAdminUsers.findByName(username)).thenReturn(null); authenticationService.checkFor(username, password); }
@Test(expected = BadCredentialsException.class) public void shouldThrowExceptionIfUserPasswordIsNotCorrect() { String username = "******"; String password = "******"; AdminUser adminUser = new AdminUser(username, password); when(allAdminUsers.findByName(username)).thenReturn(adminUser); authenticationService.checkFor(username, "notAku"); }
@Test public void shouldUseAllAdminUsersToValidateUser() { String username = "******"; String password = "******"; AdminUser adminUser = new AdminUser(username, password); when(allAdminUsers.findByName(username)).thenReturn(adminUser); AuthenticationResponse authenticationResponse = authenticationService.checkFor(username, password); assertTrue(authenticationResponse.roles().contains("admin")); }