raducotescu commented on code in PR #62:
URL: 
https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2121330810


##########
src/test/java/org/apache/sling/engine/impl/SlingHttpServletResponseImplTest.java:
##########
@@ -107,24 +107,33 @@ public void testNoViolationChecksOnCommitedResponse() {
 
     @Test
     public void testReset() {
-        final SlingHttpServletResponse orig = 
mock(SlingHttpServletResponse.class);
+        final SlingHttpServletResponse originalResponse = 
mock(SlingHttpServletResponse.class);
         final RequestData requestData = mock(RequestData.class);
-        final DispatchingInfo info = new 
DispatchingInfo(DispatcherType.INCLUDE);
-        when(requestData.getDispatchingInfo()).thenReturn(info);
-        info.setProtectHeadersOnInclude(true);
-
-        final HttpServletResponse include = new 
SlingHttpServletResponseImpl(requestData, orig);
-
-        when(orig.isCommitted()).thenReturn(false);
-        include.reset();
-        verify(orig, times(1)).isCommitted();
-        Mockito.verifyNoMoreInteractions(orig);
-
-        when(orig.isCommitted()).thenReturn(true);
-        include.reset();
-        verify(orig, times(2)).isCommitted();
-        verify(orig, times(1)).reset();
-        Mockito.verifyNoMoreInteractions(orig);
+        DispatchingInfo dispatchingInfo = new 
DispatchingInfo(DispatcherType.INCLUDE);
+        when(requestData.getDispatchingInfo()).thenReturn(dispatchingInfo);
+        dispatchingInfo.setProtectHeadersOnInclude(true);
+
+        final HttpServletResponse includeResponse = new 
SlingHttpServletResponseImpl(requestData, originalResponse);
+
+        when(originalResponse.isCommitted()).thenReturn(false);
+        includeResponse.reset();
+        verify(originalResponse, times(1)).isCommitted();
+        Mockito.verifyNoMoreInteractions(originalResponse);
+
+        when(originalResponse.isCommitted()).thenReturn(true);
+        includeResponse.reset();
+        verify(originalResponse, times(2)).isCommitted();
+        verify(originalResponse, times(1)).reset();
+        Mockito.verifyNoMoreInteractions(originalResponse);
+
+        // check if reset is called on error handling
+        dispatchingInfo = new DispatchingInfo(DispatcherType.ERROR);
+        when(requestData.getDispatchingInfo()).thenReturn(dispatchingInfo);
+        dispatchingInfo.setProtectHeadersOnInclude(true);
+        when(originalResponse.isCommitted()).thenReturn(false);
+        includeResponse.reset();
+        verify(originalResponse, times(2)).reset();
+        Mockito.verifyNoMoreInteractions(originalResponse);

Review Comment:
   I would follow through with this comment and create different mocks for each 
test.



##########
src/test/java/org/apache/sling/engine/impl/filter/ErrorFilterChainTest.java:
##########
@@ -80,4 +85,29 @@ public void testResponseNotCommitted() throws IOException, 
ServletException {
         chain2.doFilter(request, response);
         Mockito.verify(errorHandler, times(1)).handleError(anyInt(), 
anyString(), eq(request), eq(response));
     }
+
+    @Test
+    public void testResponseDispatcherInfoOnError() throws IOException, 
ServletException {
+        // mocks a final method in SlingHttpServletResponseImpl, needs 
mockito-inline
+        final DefaultErrorHandler handler = new DefaultErrorHandler();
+        final ErrorHandler errorHandler = Mockito.mock(ErrorHandler.class);
+        handler.setDelegate(errorHandler);
+
+        final SlingHttpServletRequest request = 
Mockito.mock(SlingHttpServletRequest.class);
+        final SlingHttpServletResponseImpl response = 
Mockito.mock(SlingHttpServletResponseImpl.class);
+        RequestData requestData = Mockito.mock(RequestData.class);
+        when(response.getRequestData()).thenReturn(requestData);
+
+        final ErrorFilterChain chain2 = new ErrorFilterChain(new 
FilterHandle[0], handler, 404, "not found");
+        chain2.doFilter(request, response);
+        verify(response, times(1)).reset();
+
+        // called ones with thew error dispatcher info

Review Comment:
   I don't understand this comment.



-- 
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: dev-unsubscr...@sling.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to