CheCacheDisablingFilter extends CacheDisablingFilter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { for (Pattern pattern : actionPatterns) { if (pattern.matcher(((HttpServletRequest) request).getRequestURI()).matches()) { super.doFilter(request, response, chain); return; } } chain.doFilter(request, response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }
@Test(dataProvider = "nonCachedPathProvider") public void shouldSetDisablingCacheHeaders(String uri) throws Exception { when(request.getRequestURI()).thenReturn(uri); filter.doFilter(request, response, chain); verify(response).setDateHeader(eq("Date"), anyLong()); verify(response).setDateHeader(eq("Expires"), anyLong()); verify(response).setHeader(eq("Cache-control"), eq("no-cache, no-store, must-revalidate")); verify(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class)); }
@Test(dataProvider = "cachedPathProvider") public void shouldBypassDisablingCacheHeaders(String uri) throws Exception { when(request.getRequestURI()).thenReturn(uri); filter.doFilter(request, response, chain); verify(response, never()).setHeader(eq("Cache-control"), anyString()); verify(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class)); }