Created
August 31, 2010 19:23
-
-
Save fbenevides/559574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.enovar.edashboard.service; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.times; | |
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.when; | |
import org.junit.Before; | |
import org.junit.Test; | |
import br.com.enovar.edashboard.controller.DashboardSession; | |
import br.com.enovar.edashboard.domain.User; | |
import br.com.enovar.edashboard.domain.UserRepository; | |
public class DefaultAuthenticatorTest { | |
Authenticator authenticator; | |
UserRepository userRepository; | |
DashboardSession session; | |
@Before | |
public void setUp() { | |
userRepository = mock(UserRepository.class); | |
session = mock(DashboardSession.class); | |
authenticator = new DefaultAuthenticator(session, userRepository); | |
} | |
@Test | |
public void shouldAuthenticateWhenLoginAndPasswordAreValid() { | |
String login = "benevas"; | |
String password = "1234"; | |
when(userRepository.findByLoginAndPassword(login, password)) | |
.thenReturn(User.withLoginAndPassword(login, password)); | |
authenticator.authenticate(login, password); | |
verify(userRepository, times(1)).findByLoginAndPassword(login, password); | |
} | |
@Test(expected = InvalidCredentialsException.class) | |
public void shouldNotAuthenticateWhenLoginAndPasswordAreInvalid() { | |
String login = "benevas"; | |
String password = "1234"; | |
when(userRepository.findByLoginAndPassword(login, password)).thenReturn(null); | |
authenticator.authenticate(login, password); | |
} | |
@Test | |
public void shouldLogoutCorrectlyWhenUserIsLoggedIn() { | |
authenticator.logout(); | |
verify(session, times(1)).logout(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment