From 2d27fc1d5e3825644144c81da86ea1788db6d9d2 Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Fri, 11 Feb 2022 00:52:01 +0100 Subject: [PATCH] create Account Repository for AccountServiceTest mocked --- .../hs/fulda/de/ci/exam/project/AccountServiceTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 c9f1bdc..f5ab438 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 @@ -21,10 +21,18 @@ public class AccountServiceTest { @Before public void setup() { + accountRepository = createAccountRepository(); passwordEncoder = createPasswordEncoder(); accountService = new AccountService(accountRepository, passwordEncoder); } + private AccountRepository createAccountRepository() { + AccountRepository mock = mock(AccountRepository.class); + when(mock.findById(ENABLED_USER.getId())).thenReturn(ENABLED_USER); + when(mock.findById(DISABLED_USER.getId())).thenReturn(DISABLED_USER); + return mock; + } + private PasswordEncoder createPasswordEncoder() { PasswordEncoder mock = mock(PasswordEncoder.class); when(mock.encode(anyString())).thenReturn("any password hash");