|
@ -0,0 +1,35 @@ |
|
|
|
|
|
package hs.fulda.de.ci.exam.project; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
|
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyString; |
|
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
public class AccountServiceTest { |
|
|
|
|
|
private static final String PASSWORD = "password"; |
|
|
|
|
|
|
|
|
|
|
|
private static final Account ENABLED_USER = |
|
|
|
|
|
new Account("user id", "hash", Account.AccountStatus.ACTIVE); |
|
|
|
|
|
|
|
|
|
|
|
private static final Account DISABLED_USER = |
|
|
|
|
|
new Account("disabled user id", "disabled user password hash", Account.AccountStatus.CLOSED); |
|
|
|
|
|
|
|
|
|
|
|
private AccountRepository accountRepository; |
|
|
|
|
|
private PasswordEncoder passwordEncoder; |
|
|
|
|
|
private AccountService accountService; |
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
|
public void setup() { |
|
|
|
|
|
passwordEncoder = createPasswordEncoder(); |
|
|
|
|
|
accountService = new AccountService(accountRepository, passwordEncoder); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private PasswordEncoder createPasswordEncoder() { |
|
|
|
|
|
PasswordEncoder mock = mock(PasswordEncoder.class); |
|
|
|
|
|
when(mock.encode(anyString())).thenReturn("any password hash"); |
|
|
|
|
|
when(mock.encode(PASSWORD)).thenReturn(ENABLED_USER.getPasswordHash()); |
|
|
|
|
|
return mock; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |