### Question:
DefaultRoutePlanner implements HttpRoutePlanner { @Override public final HttpRoute determineRoute(final HttpHost host, final HttpContext context) throws HttpException { if (host == null) { throw new ProtocolException("Target host is not specified"); } final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig config = clientContext.getRequestConfig(); HttpHost proxy = config.getProxy(); if (proxy == null) { proxy = determineProxy(host, context); } final HttpHost target = RoutingSupport.normalize(host, schemePortResolver); if (target.getPort() < 0) { throw new ProtocolException("Unroutable protocol scheme: " + target); } final boolean secure = target.getSchemeName().equalsIgnoreCase("https"); if (proxy == null) { return new HttpRoute(target, determineLocalAddress(target, context), secure); } return new HttpRoute(target, determineLocalAddress(proxy, context), proxy, secure); } DefaultRoutePlanner(final SchemePortResolver schemePortResolver); @Override final HttpRoute determineRoute(final HttpHost host, final HttpContext context);  }### Answer:
@Test public void testDirect() throws Exception { final HttpHost target = new HttpHost("http", "somehost", 80); final HttpContext context = new BasicHttpContext(); final HttpRoute route = routePlanner.determineRoute(target, context); Assert.assertEquals(target, route.getTargetHost()); Assert.assertEquals(1, route.getHopCount()); Assert.assertFalse(route.isSecure()); Mockito.verify(schemePortResolver, Mockito.never()).resolve(Mockito.<HttpHost>any()); }
@Test public void testDirectDefaultPort() throws Exception { final HttpHost target = new HttpHost("https", "somehost", -1); Mockito.when(schemePortResolver.resolve(target)).thenReturn(443); final HttpContext context = new BasicHttpContext(); final HttpRoute route = routePlanner.determineRoute(target, context); Assert.assertEquals(new HttpHost("https", "somehost", 443), route.getTargetHost()); Assert.assertEquals(1, route.getHopCount()); Assert.assertTrue(route.isSecure()); }
@Test public void testViaProxy() throws Exception { final HttpHost target = new HttpHost("http", "somehost", 80); final HttpHost proxy = new HttpHost("proxy", 8080); final HttpClientContext context = HttpClientContext.create(); context.setRequestConfig(RequestConfig.custom().setProxy(proxy).build()); final HttpRoute route = routePlanner.determineRoute(target, context); Assert.assertEquals(target, route.getTargetHost()); Assert.assertEquals(proxy, route.getProxyHost()); Assert.assertEquals(2, route.getHopCount()); Assert.assertFalse(route.isSecure()); Mockito.verify(schemePortResolver, Mockito.never()).resolve(Mockito.<HttpHost>any()); }
@Test(expected= ProtocolException.class) public void testNullTarget() throws Exception { final HttpContext context = new BasicHttpContext(); routePlanner.determineRoute(null, context); }