|
@ -14,6 +14,7 @@ import java.util.Base64; |
|
|
import java.util.Observable; |
|
|
import java.util.Observable; |
|
|
import java.util.Observer; |
|
|
import java.util.Observer; |
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.nullValue; |
|
|
import static org.hamcrest.MatcherAssert.assertThat; |
|
|
import static org.hamcrest.MatcherAssert.assertThat; |
|
|
import static org.hamcrest.Matchers.notNullValue; |
|
|
import static org.hamcrest.Matchers.notNullValue; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
@ -83,6 +84,28 @@ class AccessServiceTest implements Observer |
|
|
then(repository).shouldHaveNoMoreInteractions(); |
|
|
then(repository).shouldHaveNoMoreInteractions(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testUnprotectedLoginPath() |
|
|
|
|
|
{ |
|
|
|
|
|
final String path = "/accounts/login"; |
|
|
|
|
|
|
|
|
|
|
|
final AccessToken result = new AccessService(null) |
|
|
|
|
|
.before(path, null); |
|
|
|
|
|
|
|
|
|
|
|
assertNull(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testUnprotectedRegistratePath() |
|
|
|
|
|
{ |
|
|
|
|
|
final String path = "/accounts/registrate"; |
|
|
|
|
|
|
|
|
|
|
|
final AccessToken result = new AccessService(null) |
|
|
|
|
|
.before(path, null); |
|
|
|
|
|
|
|
|
|
|
|
assertNull(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
void given_newUser_when_createUser_should_storeNewUser() |
|
|
void given_newUser_when_createUser_should_storeNewUser() |
|
|
{ |
|
|
{ |
|
@ -118,6 +141,28 @@ class AccessServiceTest implements Observer |
|
|
then(repository).shouldHaveNoMoreInteractions(); |
|
|
then(repository).shouldHaveNoMoreInteractions(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void given_newUser_when_userNameAlreadyExist_should_storeNewUser() |
|
|
|
|
|
{ |
|
|
|
|
|
final RegistrateRequest request = |
|
|
|
|
|
RegistrateRequest.of("testUser", "testPwd"); |
|
|
|
|
|
|
|
|
|
|
|
final AccessRepository repository = mock(AccessRepository.class); |
|
|
|
|
|
when(repository.findByUserName(any())) |
|
|
|
|
|
.thenReturn(new Access()); |
|
|
|
|
|
|
|
|
|
|
|
final AccessService service = new AccessService(repository); |
|
|
|
|
|
service.addObserver(this); |
|
|
|
|
|
|
|
|
|
|
|
final boolean result = service.createPlayer(request); |
|
|
|
|
|
|
|
|
|
|
|
assertFalse(result); |
|
|
|
|
|
assertThat("No event thrown", this.event, nullValue()); |
|
|
|
|
|
|
|
|
|
|
|
then(repository).should().findByUserName(any()); |
|
|
|
|
|
then(repository).shouldHaveNoMoreInteractions(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
void given_loggedInUser_when_logout_should_logoutUser() |
|
|
void given_loggedInUser_when_logout_should_logoutUser() |
|
|
{ |
|
|
{ |
|
|