Browse Source

account should be invalid for invalid password

feature-pr-AccountService
Sona Markosyan 3 years ago
parent
commit
646a6a0342
  1. 17
      src/test/java/hs/fulda/de/ci/exam/project/AccountServiceTest.java

17
src/test/java/hs/fulda/de/ci/exam/project/AccountServiceTest.java

@ -2,10 +2,10 @@ package hs.fulda.de.ci.exam.project;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder; import org.mockito.InOrder;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -68,6 +68,19 @@ public class AccountServiceTest {
verify(accountRepository).findById(DISABLED_USER.getId()); verify(accountRepository).findById(DISABLED_USER.getId());
verify(passwordEncoder, never()).encode(anyString()); verify(passwordEncoder, never()).encode(anyString());
} }
@Test
public void shouldBeInvalidForInvalidPassword() {
boolean accountIsValid =
accountService.isValidAccount(ENABLED_USER.getId(), "invalid");
assertFalse(accountIsValid);
ArgumentCaptor<String> passwordCaptor = ArgumentCaptor.forClass(String.class);
verify(passwordEncoder).encode(passwordCaptor.capture());
assertEquals("invalid", passwordCaptor.getValue());
}
private AccountRepository createAccountRepository() { private AccountRepository createAccountRepository() {
AccountRepository mock = mock(AccountRepository.class); AccountRepository mock = mock(AccountRepository.class);
when(mock.findById(ENABLED_USER.getId())).thenReturn(ENABLED_USER); when(mock.findById(ENABLED_USER.getId())).thenReturn(ENABLED_USER);

Loading…
Cancel
Save