|
@ -13,6 +13,8 @@ import spark.Request; |
|
|
import spark.Response; |
|
|
import spark.Response; |
|
|
import spark.Session; |
|
|
import spark.Session; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.BDDMockito.then; |
|
|
import static org.mockito.BDDMockito.then; |
|
@ -159,4 +161,40 @@ class AccessControllerTest |
|
|
|
|
|
|
|
|
assertEquals(Integer.valueOf(401), statusCaptor.getValue(), "Should return Status code 401."); |
|
|
assertEquals(Integer.valueOf(401), statusCaptor.getValue(), "Should return Status code 401."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void registrateTest() throws IOException |
|
|
|
|
|
{ |
|
|
|
|
|
when(request.body()).thenReturn("{\"userName\":\"TestName\",\"password\":\"TestPassword\"}"); |
|
|
|
|
|
|
|
|
|
|
|
when(service.createPlayer(any())).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
|
|
|
|
new AccessController(service).registrate(request, response); |
|
|
|
|
|
|
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
then(service).should().createPlayer(any()); |
|
|
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
|
|
assertEquals(Integer.valueOf(201), statusCaptor.getValue(), "Should return Status code 201."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void failedRegistrateTest() throws IOException |
|
|
|
|
|
{ |
|
|
|
|
|
when(request.body()).thenReturn("{\"userName\":\"TestName\",\"password\":\"TestPassword\"}"); |
|
|
|
|
|
|
|
|
|
|
|
when(service.createPlayer(any())).thenReturn(false); |
|
|
|
|
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
|
|
|
|
new AccessController(service).registrate(request, response); |
|
|
|
|
|
|
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
then(service).should().createPlayer(any()); |
|
|
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
|
|
assertEquals(Integer.valueOf(400), statusCaptor.getValue(), "Should return Status code 400."); |
|
|
|
|
|
} |
|
|
} |
|
|
} |