Browse Source

account should be invalid for invalid credentials

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

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

@ -2,7 +2,9 @@ package hs.fulda.de.ci.exam.project;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
@ -37,6 +39,26 @@ public class AccountServiceTest {
verify(passwordEncoder).encode(PASSWORD);
}
@Test
public void shouldBEInvalidForInvalidId() {
boolean accountIsValid = accountService.isValidAccount("invalid id", PASSWORD);
assertFalse(accountIsValid);
InOrder inOrder = inOrder(accountRepository, passwordEncoder);
inOrder.verify(accountRepository).findById("invalid id");
inOrder.verify(passwordEncoder, never()).encode(anyString());
}
@Test
public void shouldBeInvalidForInvalid(){
boolean accountIsValid = accountService.isValidAccount("invalid id", PASSWORD);
assertFalse(accountIsValid);
InOrder inOrder = inOrder(accountRepository, passwordEncoder);
inOrder.verify(accountRepository).findById("invalid id");
inOrder.verify(passwordEncoder, never()).encode(anyString());
}
private AccountRepository createAccountRepository() {
AccountRepository mock = mock(AccountRepository.class);
when(mock.findById(ENABLED_USER.getId())).thenReturn(ENABLED_USER);

Loading…
Cancel
Save