joerghoh commented on code in PR #105:
URL: 
https://github.com/apache/sling-org-apache-sling-engine/pull/105#discussion_r4537056110


##########
src/test/java/org/apache/sling/engine/impl/DefaultErrorHandlerTest.java:
##########
@@ -101,6 +105,32 @@ public void 
testHandleStatusWithoutDelegateStillRendersMessage() throws Exceptio
         assertFalse("response body must not contain a server/address footer", 
body.contains("<address>"));
     }
 
+    @Test
+    public void 
testHandleStatusWithoutDelegateForNonHtmlRequestDoesNotRenderBody() throws 
Exception {
+        when(request.getHeader("Accept")).thenReturn("application/json");
+
+        handler.handleError(404, "not found", request, response);
+
+        verify(response).setStatus(404);
+        verify(response).setContentType(null);
+        verify(response).flushBuffer();
+        verify(response, never()).getWriter();
+        assertEquals("", responseBody.toString());
+    }
+
+    @Test
+    public void 
testHandleThrowableWithoutDelegateForNonHtmlRequestDoesNotRenderBody() throws 
Exception {
+        when(request.getHeader("Accept")).thenReturn("text/plain");
+
+        handler.handleError(new IllegalStateException("some internal detail"), 
request, response);
+
+        verify(response).setStatus(500);
+        verify(response).setContentType(null);

Review Comment:
   the above code never sets the content type. this verification will fail.



##########
src/test/java/org/apache/sling/engine/impl/DefaultErrorHandlerTest.java:
##########
@@ -101,6 +105,32 @@ public void 
testHandleStatusWithoutDelegateStillRendersMessage() throws Exceptio
         assertFalse("response body must not contain a server/address footer", 
body.contains("<address>"));
     }
 
+    @Test
+    public void 
testHandleStatusWithoutDelegateForNonHtmlRequestDoesNotRenderBody() throws 
Exception {
+        when(request.getHeader("Accept")).thenReturn("application/json");
+
+        handler.handleError(404, "not found", request, response);
+
+        verify(response).setStatus(404);
+        verify(response).setContentType(null);

Review Comment:
   the above code never sets the content type. this verification will fail.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to