Skip to content
Snippets Groups Projects
Commit 1a6b3691 authored by Tomas Madeja's avatar Tomas Madeja
Browse files

test: league manager create if username exists

parent 70434e31
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.icehockeymanager.services;
import cz.muni.fi.pa165.icehockeymanager.config.ApplicationConfig;
import cz.muni.fi.pa165.icehockeymanager.dao.UserAuthDao;
import cz.muni.fi.pa165.icehockeymanager.exceptions.UsernameTakenException;
import cz.muni.fi.pa165.icehockeymanager.model.User;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
......@@ -14,11 +15,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.persistence.EntityExistsException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
......@@ -98,6 +102,19 @@ class UserAuthServiceImplTest {
).isNotEmpty();
}
@Test
public void createNewLeagueManagerUsernameExists() {
ArgumentCaptor<User> valueCapture = ArgumentCaptor.forClass(User.class);
doAnswer(
(invocation) -> {
throw new EntityExistsException();
}
).when(userAuthDaoMock).create(valueCapture.capture());
assertThatExceptionOfType(UsernameTakenException.class)
.isThrownBy(() -> authService.createLeagueManager(NEW_USERNAME, NEW_PASSWORD));
}
private void buildMockDB() {
String password = argonEncoder.encodePassword(CORRECT_PASSWORD);
user1 = buildUser(1L, CORRECT_USERNAME, password);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment