diff --git a/src/main/java/hs/fulda/de/ci/exam/project/AccountRepository.java b/src/main/java/hs/fulda/de/ci/exam/project/AccountRepository.java index 90a96db..6cec755 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/AccountRepository.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/AccountRepository.java @@ -25,10 +25,15 @@ public class AccountRepository { public Collection 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)); + } } diff --git a/src/main/java/hs/fulda/de/ci/exam/project/AccountService.java b/src/main/java/hs/fulda/de/ci/exam/project/AccountService.java index 051e0b9..814d4c2 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/AccountService.java +++ b/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; } diff --git a/src/test/java/hs/fulda/de/ci/exam/project/AccountServiceTest.java b/src/test/java/hs/fulda/de/ci/exam/project/AccountServiceTest.java index dfbe67e..3d1d7dd 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/AccountServiceTest.java +++ b/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)); + } + }