Browse Source

verify create account

feature-pr-AccountService
Sona Markosyan 3 years ago
parent
commit
0ebcc656f8
  1. 7
      src/main/java/hs/fulda/de/ci/exam/project/AccountRepository.java
  2. 3
      src/main/java/hs/fulda/de/ci/exam/project/AccountService.java
  3. 14
      src/test/java/hs/fulda/de/ci/exam/project/AccountServiceTest.java

7
src/main/java/hs/fulda/de/ci/exam/project/AccountRepository.java

@ -25,10 +25,15 @@ public class AccountRepository {
public Collection<Account> findAll() {
return accountList.values();
}
public void save(Account account){
public boolean save(Account account){
accountList.put(generateKey(account), account);
return true;
}
public void addPersonalDetails(Person person, String id){
personalInfo.put(accountList.get(id), person);
}
public void delete(Account account) {
accountList.remove(generateKey(account));
}
}

3
src/main/java/hs/fulda/de/ci/exam/project/AccountService.java

@ -34,11 +34,12 @@ public class AccountService {
throw new RuntimeException("Account Already Exists");
}
}
public void createAccount(String id, String password, Account.AccountStatus accountStatus){
public boolean createAccount(String id, String password, Account.AccountStatus accountStatus){
Account account = new Account(id, password, accountStatus);
validateAccount(account);
checkIfAccountAlreadyExist(account);
accountRepository.save(account);
return true;
}

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

@ -9,6 +9,8 @@ import org.mockito.InOrder;
import java.util.ArrayList;
import java.util.Date;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
@ -123,4 +125,16 @@ public class AccountServiceTest {
});
}
@Test
public void verifyCreateAccount() {
when(accountRepository.save(any(Account.class))).thenReturn(true);
assertTrue(accountService.createAccount("John", "pwd", Account.AccountStatus.ACTIVE));
verify(accountRepository).save(any(Account.class));
verify(accountRepository, times(1)).checkIfAccountAlreadyExist(any(Account.class));
verify(accountRepository, never()).delete(any(Account.class));
}
}
Loading…
Cancel
Save