Browse Source

extract getUser routing to ServerApp

chore-betterServerTestCoverage
Steffen Nitschke 4 years ago
parent
commit
d6046257e5
  1. 1
      fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java
  2. 12
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/web/UserController.java
  3. 15
      fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java

1
fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java

@ -48,6 +48,7 @@ public class ServerApp
post("/users", userController::updateUser);
get("/users", userController::getCompleteUser);
get("/users/:user_id", userController::getUser);
get("/hello", (req, res) -> "Hello World");

12
fh.fd.ci.server/src/main/java/de/fd/fh/server/user/web/UserController.java

@ -6,12 +6,11 @@ import de.fd.fh.server.access.AccessToken;
import de.fd.fh.server.user.User;
import de.fd.fh.server.user.UserId;
import de.fd.fh.server.user.UserService;
import lombok.RequiredArgsConstructor;
import spark.Request;
import spark.Response;
import static spark.Spark.get;
import static spark.Spark.post;
@RequiredArgsConstructor
public class UserController
{
private ObjectMapper objectMapper = new ObjectMapper();
@ -88,11 +87,4 @@ public class UserController
return response;
}
public UserController(final UserService service)
{
this.service = service;
get("/users/:user_id", this::getUser);
}
}

15
fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java

@ -148,4 +148,19 @@ class ServerAppTest
assertEquals(200, res.getStatus());
then(userController).should().getCompleteUser(any(), any());
}
@Test
void getPlayer() throws JsonProcessingException
{
when(userController.getUser(any(), any())).thenReturn(mock(Response.class));
String url = "/users/12345";
ApiTestUtils.TestResponse<String> res = new ApiTestUtils<String>()
.request("GET", url, null, null, String.class);
assertNotNull(res);
assertEquals(200, res.getStatus());
then(userController).should().getUser(any(), any());
}
}
Loading…
Cancel
Save