ExceptionLoggingFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { try { filterChain.doFilter(servletRequest, servletResponse); } catch (IOException e) { logIOException(e, servletRequest, servletResponse); throw e; } catch (ServletException e) { logServletException(e, servletRequest, servletResponse); throw e; } catch (RuntimeException e) { logRuntimeException(e, servletRequest, servletResponse); throw e; } }  void setExceptionLogger(final ExceptionLogger exceptionLogger); @Override void doFilter(ServletRequest servletRequest,
            ServletResponse servletResponse,
            FilterChain filterChain);  }
@Test public void testDoFilter_normal() throws IOException, ServletException { testTarget.doFilter(mockRequest, mockResponse, mockFilterChain); verify(mockFilterChain, times(1)).doFilter(mockRequest, mockResponse); }
@Test public void testDoFilter_occur_ioexception() throws IOException, ServletException { IOException occurException = new IOException("io exception."); doThrow(occurException).when(mockFilterChain).doFilter(mockRequest, mockResponse); try { testTarget.doFilter(mockRequest, mockResponse, mockFilterChain); } catch (IOException e) { assertSame(occurException, e); } verify(mockExceptionLogger, times(1)).error(occurException); }
@Test public void testDoFilter_occur_servletexception() throws IOException, ServletException { ServletException occurException = new ServletException("servlet exception."); doThrow(occurException).when(mockFilterChain).doFilter(mockRequest, mockResponse); try { testTarget.doFilter(mockRequest, mockResponse, mockFilterChain); } catch (ServletException e) { assertSame(occurException, e); } verify(mockExceptionLogger, times(1)).error(occurException); }
@Test public void testDoFilter_occur_runtimeexception() throws IOException, ServletException { NullPointerException occurException = new NullPointerException("null pointer exception."); doThrow(occurException).when(mockFilterChain).doFilter(mockRequest, mockResponse); try { testTarget.doFilter(mockRequest, mockResponse, mockFilterChain); } catch (NullPointerException e) { assertSame(occurException, e); } verify(mockExceptionLogger, times(1)).error(occurException); }
@Test public void testDoFilter_occur_error() throws IOException, ServletException { OutOfMemoryError occurError = new OutOfMemoryError("out of memory error."); doThrow(occurError).when(mockFilterChain).doFilter(mockRequest, mockResponse); try { testTarget.doFilter(mockRequest, mockResponse, mockFilterChain); } catch (OutOfMemoryError e) { assertSame(occurError, e); } verify(mockExceptionLogger, times(0)).error((Exception) any()); }