RollbarFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { chain.doFilter(request, response); } catch (Exception e) { sendToRollbar(e); throw e; } } RollbarFilter();  RollbarFilter(Rollbar rollbar); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }
@Test public void shouldLogError() throws Exception { try { sut.doFilter(request, response, chain); } catch (Exception e) { if(!e.equals(ERROR)) { fail(); } } verify(rollbar).error(ERROR); }
@Test public void shouldSwallowException() throws Exception { doThrow(new RuntimeException("Error sending to Rollbar")).when(rollbar). error(any(Throwable.class)); try { sut.doFilter(request, response, chain); } catch (Exception e) { if(!e.equals(ERROR)) { fail(); } } }