verify encoding and content type

This commit is contained in:
Sebastian Sdorra
2019-02-01 09:42:19 +01:00
parent 34542e5cf1
commit 0a29f41835
2 changed files with 9 additions and 1 deletions

View File

@@ -81,7 +81,6 @@ public class I18nServlet extends HttpServlet {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setContentType("application/json"); response.setContentType("application/json");
try (PrintWriter out = response.getWriter()) { try (PrintWriter out = response.getWriter()) {
response.setContentType("application/json");
String path = req.getServletPath(); String path = req.getServletPath();
Function<String, Optional<JsonNode>> jsonFileProvider = usedPath -> Optional.empty(); Function<String, Optional<JsonNode>> jsonFileProvider = usedPath -> Optional.empty();
BiConsumer<String, JsonNode> createdJsonFileConsumer = (usedPath, jsonNode) -> log.debug("A json File is created from the path {}", usedPath); BiConsumer<String, JsonNode> createdJsonFileConsumer = (usedPath, jsonNode) -> log.debug("A json File is created from the path {}", usedPath);

View File

@@ -194,6 +194,8 @@ public class I18nServletTest {
assertJson(json); assertJson(json);
verify(cache).get(path); verify(cache).get(path);
verify(cache).put(eq(path), any()); verify(cache).put(eq(path), any());
verifyHeaders(response);
} }
@Test @Test
@@ -221,6 +223,8 @@ public class I18nServletTest {
verify(cache, never()).put(eq(path), any()); verify(cache, never()).put(eq(path), any());
verify(cache).get(path); verify(cache).get(path);
assertJson(json); assertJson(json);
verifyHeaders(response);
} }
@Test @Test
@@ -234,6 +238,11 @@ public class I18nServletTest {
assertJson(jsonNodeOptional.orElse(null)); assertJson(jsonNodeOptional.orElse(null));
} }
private void verifyHeaders(HttpServletResponse response) {
verify(response).setCharacterEncoding("UTF-8");
verify(response).setContentType("application/json");
}
public void assertJson(JsonNode actual) throws IOException { public void assertJson(JsonNode actual) throws IOException {
assertJson(actual.toString()); assertJson(actual.toString());
} }