@Test
public void testAuthScopeRemotePortWhenDirect() throws Exception {

    HttpRequest request = new BasicHttpRequest("GET", "/stuff");
    this.target = new HttpHost("localhost.local");
    HttpRoute route = new HttpRoute(this.target, null, false);
    HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
    Mockito.when(conn.getRoute()).thenReturn(route);
    Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
    Mockito.when(conn.getRemoteAddress()).thenReturn(InetAddress.getByName("localhost"));
    Mockito.when(conn.getRemotePort()).thenReturn(1234);
    HttpContext context = new BasicHttpContext();
    context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
    HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);
    CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
            ClientContext.COOKIE_ORIGIN);
    Assert.assertNotNull(cookieOrigin);
    Assert.assertEquals(this.target.getHostName(), cookieOrigin.getHost());
    Assert.assertEquals(1234, cookieOrigin.getPort());
    Assert.assertEquals("/stuff", cookieOrigin.getPath());
    Assert.assertFalse(cookieOrigin.isSecure());
}