Professional Documents
Culture Documents
fresco;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@BeforeClass
public static void setUp() {
authenticatorMock = mock(UserAuthenticatorInterface.class);
@Before
public void setUpAuthenticator() {
authenticator.setUserAuthenticator(authenticatorMock);
}
@Test(expected=FailedToAuthenticateException.class)
public void testAuthenticate_InvalidCredentials() throws
FailedToAuthenticateException {
doThrow(new
FailedToAuthenticateException(errorMessage)).when(authenticatorMock).authenticateUs
er("User1","wrong password"));
authenticator.authenticateUser(username, password);
@Test
public void testAuthenticate_ValidCredentials() throws
FailedToAuthenticateException {
when(authenticatorMock.authenticateUser(username, password)).thenReturn(true);
assertTrue(authenticator.authenticateUser(username, password));
@Test(expected=FailedToAuthenticateException.class)
public void testAuthenticate_EmptyCredentials() throws
FailedToAuthenticateException {
when(authenticatorMock.authenticateUser(username, password)).thenThrow(new
FailedToAuthenticateException(errorMessage));
authenticator.authenticateUser(username, password);