Loading service/src/test/java/cz/muni/fi/pa165/icehockeymanager/services/UserAuthServiceImplTest.java +17 −4 Original line number Original line Diff line number Diff line Loading @@ -48,15 +48,28 @@ class UserAuthServiceImplTest { @Test @Test public void authenticateCorrectPassword() { public void authenticateCorrectPassword() { buildMockDB(); softly.assertThat( authService.authenticateUser(CORRECT_USERNAME, CORRECT_PASSWORD) ).isTrue(); } @Test public void authenticateIncorrectPassword() { buildMockDB(); softly.assertThat( authService.authenticateUser(CORRECT_USERNAME, INCORRECT_PASSWORD) ).isFalse(); } private void buildMockDB() { String password = argonEncoder.encodePassword(CORRECT_PASSWORD); String password = argonEncoder.encodePassword(CORRECT_PASSWORD); var user = buildUser(1L, CORRECT_USERNAME, password); var user = buildUser(1L, CORRECT_USERNAME, password); when(userAuthDaoMock.findByUsername(CORRECT_USERNAME)) when(userAuthDaoMock.findByUsername(CORRECT_USERNAME)) .thenReturn(Optional.of(user)); .thenReturn(Optional.of(user)); softly.assertThat( authService.authenticateUser(CORRECT_USERNAME, CORRECT_PASSWORD) ).isTrue(); } } private static User buildUser(Long id, String username, String passwordHash) { private static User buildUser(Long id, String username, String passwordHash) { Loading Loading
service/src/test/java/cz/muni/fi/pa165/icehockeymanager/services/UserAuthServiceImplTest.java +17 −4 Original line number Original line Diff line number Diff line Loading @@ -48,15 +48,28 @@ class UserAuthServiceImplTest { @Test @Test public void authenticateCorrectPassword() { public void authenticateCorrectPassword() { buildMockDB(); softly.assertThat( authService.authenticateUser(CORRECT_USERNAME, CORRECT_PASSWORD) ).isTrue(); } @Test public void authenticateIncorrectPassword() { buildMockDB(); softly.assertThat( authService.authenticateUser(CORRECT_USERNAME, INCORRECT_PASSWORD) ).isFalse(); } private void buildMockDB() { String password = argonEncoder.encodePassword(CORRECT_PASSWORD); String password = argonEncoder.encodePassword(CORRECT_PASSWORD); var user = buildUser(1L, CORRECT_USERNAME, password); var user = buildUser(1L, CORRECT_USERNAME, password); when(userAuthDaoMock.findByUsername(CORRECT_USERNAME)) when(userAuthDaoMock.findByUsername(CORRECT_USERNAME)) .thenReturn(Optional.of(user)); .thenReturn(Optional.of(user)); softly.assertThat( authService.authenticateUser(CORRECT_USERNAME, CORRECT_PASSWORD) ).isTrue(); } } private static User buildUser(Long id, String username, String passwordHash) { private static User buildUser(Long id, String username, String passwordHash) { Loading