PathSegmentNumberFilter implements RequestFilter { @Override public boolean shouldSkip(HttpServletRequest request) { List<PathSegment> pathSegments = UriComponent.parsePathSegments(request.getRequestURI(), false); int notEmptyPathSergments = 0; for (PathSegment pathSegment : pathSegments) { if (pathSegment.getPath() != null && !pathSegment.getPath().isEmpty()) { notEmptyPathSergments++; } } return notEmptyPathSergments == segmentNumber; } PathSegmentNumberFilter(int segmentNumber); @Override boolean shouldSkip(HttpServletRequest request);  }
@Test(dataProvider = "notskip") public void testShouldSkip(String requestUri) throws Exception { HttpServletRequest request = new MockHttpServletRequest("http: PathSegmentNumberFilter filter = new PathSegmentNumberFilter(3); boolean result = filter.shouldSkip(request); Assert.assertTrue(result); }
@Test(dataProvider = "skip") public void testShouldNotSkip(String requestUri) throws Exception { HttpServletRequest request = new MockHttpServletRequest("http: PathSegmentNumberFilter filter = new PathSegmentNumberFilter(2); boolean result = filter.shouldSkip(request); Assert.assertFalse(result); }