ServletContextHelper { public List<FilterMapping> getFilterMappingsForPath(final ServletContext servletContext, final String path) { Objects.requireNonNull(servletContext); String inContextPath = getPathInContext(servletContext, path); List<FilterMapping> filterMappings = new ArrayList<>(); for (FilterMapping filterMapping : servletContext.getFilterMappings()) { if (filterMapping.getUrlPattern().matcher(inContextPath).matches()) { if (filterMapping.getUrlExcludePattern() != null) { if (!filterMapping.getUrlExcludePattern().matcher(inContextPath).matches()) { filterMappings.add(filterMapping); } } else { filterMappings.add(filterMapping); } } } return filterMappings; }  ServletMapping getResolvedServletMapping(final ServletContext servletContext, final String path); ServletContextImpl getResolvedContext(final List<ServletContextImpl> servletContexts, final String path); List<FilterMapping> getFilterMappingsForPath(final ServletContext servletContext, final String path);  }
@Test public void shouldReturnEmptyCollectionForNoFilters() { assertThat(servletContextHelper.getFilterMappingsForPath(servletContext, "/context/"), hasSize(0)); }
@Test public void shouldReturnFilteredFilters() { List<FilterMapping> filterMappings = new ArrayList<>(); filterMappings.add(new FilterMappingImpl(Pattern.compile("^/secured/.*$"), null, FakeAbstractFilter.class)); filterMappings.add(new FilterMappingImpl(Pattern.compile("^/secured/abc.*$"), null, FakeAbstractFilter.class)); filterMappings.add(new FilterMappingImpl(Pattern.compile("^/demo/.*$"), null, FakeAbstractFilter.class)); when(servletContext.getFilterMappings()).thenReturn(filterMappings); assertThat(servletContextHelper.getFilterMappingsForPath(servletContext, "/context/secured/abc"), hasSize(2)); }
@Test public void shouldReturnFilteredFiltersWithExclude() { List<FilterMapping> filterMappings = new ArrayList<>(); filterMappings.add(new FilterMappingImpl(Pattern.compile("^/secured/.*$"), null, FakeAbstractFilter.class)); filterMappings.add(new FilterMappingImpl(Pattern.compile("^/secured/abc.*$"), Pattern.compile("^/secured/abc/exclude.*$"), FakeAbstractFilter.class)); filterMappings.add(new FilterMappingImpl(Pattern.compile("^/demo/.*$"), null, FakeAbstractFilter.class)); when(servletContext.getFilterMappings()).thenReturn(filterMappings); assertThat(servletContextHelper.getFilterMappingsForPath(servletContext, "/context/secured/abc/excluded"), hasSize(1)); }