public final static boolean checkVia(final RouteTracker rt, final HttpRoute r,
                                         final HttpRouteDirector rd, final int steps) {

        final String msg = r + " @ " + rt;

        boolean complete = false;
        int n = steps;
        while (!complete && n > 0) {

            final int action = rd.nextStep(r, rt.toRoute());
            switch (action) {

                case HttpRouteDirector.COMPLETE:
                    complete = true;
                    Assertions.assertEquals(r, rt.toRoute());
                    break;

                case HttpRouteDirector.CONNECT_TARGET: {
                    final boolean sec = r.isSecure();
                    rt.connectTarget(sec);
                    checkCTLS(rt, true, false, false, sec);
                    Assertions.assertEquals(1, rt.getHopCount(), "wrong hop count " + msg);
                    Assertions.assertEquals(r.getTargetHost(), rt.getHopTarget(0), "wrong hop0 " + msg);
                }
                break;

                case HttpRouteDirector.CONNECT_PROXY: {
                    // we assume an insecure proxy connection
                    final boolean sec = false;
                    rt.connectProxy(r.getProxyHost(), sec);
                    checkCTLS(rt, true, false, false, sec);
                    Assertions.assertEquals(2, rt.getHopCount(), "wrong hop count " + msg);
                    Assertions.assertEquals(r.getProxyHost(), rt.getHopTarget(0), "wrong hop0 " + msg);
                    Assertions.assertEquals(r.getTargetHost(), rt.getHopTarget(1), "wrong hop1 " + msg);
                }
                break;

                case HttpRouteDirector.TUNNEL_TARGET: {
                    final int hops = rt.getHopCount();
                    // we assume an insecure tunnel
                    final boolean sec = false;
                    rt.tunnelTarget(sec);
                    checkCTLS(rt, true, true, false, sec);
                    Assertions.assertEquals(hops, rt.getHopCount(), "wrong hop count " + msg);
                    Assertions.assertEquals(r.getProxyHost(), rt.getHopTarget(0), "wrong hop0 " + msg);
                    Assertions.assertEquals(r.getTargetHost(), rt.getHopTarget(hops - 1), "wrong hopN " + msg);
                }
                break;

                case HttpRouteDirector.TUNNEL_PROXY: {
                    final int hops = rt.getHopCount(); // before tunnelling
                    // we assume an insecure tunnel
                    final boolean sec = false;
                    final HttpHost pxy = r.getHopTarget(hops - 1);
                    rt.tunnelProxy(pxy, sec);
                    // Since we're tunnelling to a proxy and not the target,
                    // the 'tunelling' flag is false: no end-to-end tunnel.
                    checkCTLS(rt, true, false, false, sec);
                    Assertions.assertEquals(hops + 1, rt.getHopCount(), "wrong hop count " + msg);
                    Assertions.assertEquals(r.getProxyHost(), rt.getHopTarget(0), "wrong hop0 " + msg);
                    Assertions.assertEquals(pxy, rt.getHopTarget(hops - 1), "wrong hop" + hops + " " + msg);
                    Assertions.assertEquals(r.getTargetHost(), rt.getHopTarget(hops), "wrong hopN " + msg);
                }
                break;

                case HttpRouteDirector.LAYER_PROTOCOL: {
                    final int hops = rt.getHopCount();
                    final boolean tun = rt.isTunnelled();
                    final boolean sec = r.isSecure();
                    rt.layerProtocol(sec);
                    checkCTLS(rt, true, tun, true, sec);
                    Assertions.assertEquals(hops, rt.getHopCount(), "wrong hop count " + msg);
                    Assertions.assertEquals(r.getProxyHost(), rt.getProxyHost(), "wrong proxy " + msg);
                    Assertions.assertEquals(r.getTargetHost(), rt.getTargetHost(), "wrong target " + msg);
                }
                break;


                // UNREACHABLE
                default:
                    Assertions.fail("unexpected action " + action + " from director, " + msg);
                    break;

            } // switch
            n--;
        }

        return complete;
    }
Helper to check tracking of a route.
This uses a {@link HttpRouteDirector} to fake establishing the route,
checking the intermediate steps.

@param rt        the tracker to check with
@param r         the route to establish
@param rd        the director to check with
@param steps     the step count for this invocation

@return  {@code true} iff the route is complete
httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteTracker.java