ClientConnectionManagerFactory { public static HttpClientConnectionManager wrap (HttpClientConnectionManager orig) { if (orig instanceof Wrapped) throw new IllegalArgumentException(); final Class<?>[] interfaces; if (orig instanceof ConnPoolControl) { interfaces = new Class<?>[]{ HttpClientConnectionManager.class, ConnPoolControl.class, Wrapped.class }; } else { interfaces = new Class<?>[]{ HttpClientConnectionManager.class, Wrapped.class }; } return (HttpClientConnectionManager) Proxy.newProxyInstance( ClientConnectionManagerFactory.class.getClassLoader(), interfaces, new Handler(orig)); }  static HttpClientConnectionManager wrap(HttpClientConnectionManager orig);  }
@Test public void wrapOnce() { HttpClientConnectionManager wrapped = ClientConnectionManagerFactory.wrap(noop); assertTrue(wrapped instanceof Wrapped); }
@Test(expected = IllegalArgumentException.class) public void wrapTwice() { HttpClientConnectionManager wrapped = ClientConnectionManagerFactory.wrap(noop); ClientConnectionManagerFactory.wrap(wrapped); }