Steffen Nitschke
4 years ago
2 changed files with 97 additions and 33 deletions
-
54fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java
-
76fh.fd.ci.server/src/test/java/de/fd/fh/server/access/web/AccessControllerTest.java
@ -0,0 +1,76 @@ |
|||||
|
package de.fd.fh.server.access.web; |
||||
|
|
||||
|
import de.fd.fh.server.access.AccessService; |
||||
|
import de.fd.fh.server.access.AccessToken; |
||||
|
import org.junit.jupiter.api.BeforeEach; |
||||
|
import org.junit.jupiter.api.Test; |
||||
|
import org.mockito.ArgumentCaptor; |
||||
|
import org.mockito.Mock; |
||||
|
import org.mockito.MockitoAnnotations; |
||||
|
import spark.Request; |
||||
|
import spark.Response; |
||||
|
import spark.Session; |
||||
|
|
||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||
|
import static org.mockito.ArgumentMatchers.any; |
||||
|
import static org.mockito.BDDMockito.then; |
||||
|
import static org.mockito.Mockito.verify; |
||||
|
import static org.mockito.Mockito.when; |
||||
|
|
||||
|
class AccessControllerTest |
||||
|
{ |
||||
|
@Mock |
||||
|
Request request; |
||||
|
@Mock |
||||
|
Response response; |
||||
|
@Mock |
||||
|
Session session; |
||||
|
@Mock |
||||
|
AccessService service; |
||||
|
|
||||
|
@BeforeEach |
||||
|
void before() |
||||
|
{ |
||||
|
MockitoAnnotations.openMocks(this); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
void deletePlayerTest() |
||||
|
{ |
||||
|
when(request.params(any())).thenReturn("12345"); |
||||
|
when(request.session()).thenReturn(session); |
||||
|
when(session.attribute(any())).thenReturn(new AccessToken()); |
||||
|
when(service.deleteAccount(any(), any())).thenReturn(true); |
||||
|
|
||||
|
final ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class); |
||||
|
|
||||
|
new AccessController(service).deletePlayer(request, response); |
||||
|
|
||||
|
verify(response).status(captor.capture()); |
||||
|
|
||||
|
then(service).should().deleteAccount(any(), any()); |
||||
|
then(service).shouldHaveNoMoreInteractions(); |
||||
|
|
||||
|
assertEquals(captor.getValue(), Integer.valueOf(200), "Should return Status code 200."); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
void failedDeletePlayerTest() |
||||
|
{ |
||||
|
when(request.params(any())).thenReturn("12345"); |
||||
|
when(request.session()).thenReturn(session); |
||||
|
when(session.attribute(any())).thenReturn(new AccessToken()); |
||||
|
when(service.deleteAccount(any(), any())).thenReturn(false); |
||||
|
|
||||
|
final ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class); |
||||
|
|
||||
|
new AccessController(service).deletePlayer(request, response); |
||||
|
|
||||
|
verify(response).status(captor.capture()); |
||||
|
|
||||
|
then(service).should().deleteAccount(any(), any()); |
||||
|
then(service).shouldHaveNoMoreInteractions(); |
||||
|
|
||||
|
assertEquals(captor.getValue(), Integer.valueOf(400), "Should return Status code 400."); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue