PathComparator implements BiPredicate<InternalRoute, InternalRequest<?>> { @Override public boolean test(InternalRoute route, InternalRequest<?> request) { List<String> pathParts = request.getPathParts(); List<RoutePart<?>> routeParts = route.getRouteParts(); if (routeParts.size() != pathParts.size()) { return false; } request.setSelectedRoute(route); return StreamUtils.zip(routeParts.stream(), pathParts.stream(), PathComparator::compareParts) .allMatch(result -> result); }  @Override boolean test(InternalRoute route, InternalRequest<?> request);  }
@Test public void same_path() { InternalRoute route = basicRoute("/services/jokes/single"); RequestStub req = new RequestStub(); req.setPath("/services/jokes/single"); boolean result = testedClass.test(route, req); assertTrue(result); }
@Test public void with_params() { InternalRoute route = basicRoute("/services/jokes/{joke_id}/paragraph/{par_id}"); RequestStub req = new RequestStub(); req.setPath("/services/jokes/1/paragraph/15"); boolean result = testedClass.test(route, req); assertTrue(result); }
@Test public void wrong_part_count() { InternalRoute route = basicRoute("/services/jokes/{joke_id}"); RequestStub req = new RequestStub(); req.setPath("/services/jokes/1/paragraph/15"); boolean result = testedClass.test(route, req); assertFalse(result); }
@Test public void not_same() { InternalRoute route = basicRoute("/services/jokes"); RequestStub req = new RequestStub(); req.setPath("/services/jokes/single"); boolean result = testedClass.test(route, req); assertFalse(result); }