ClientConnectionRequestFactory { static ConnectionRequest wrap(ConnectionRequest orig) { if (orig instanceof Wrapped) throw new IllegalArgumentException(); return (ConnectionRequest) Proxy.newProxyInstance( ClientConnectionRequestFactory.class.getClassLoader(), interfaces, new Handler(orig)); }    }
@Test public void wrapOnce() { ConnectionRequest wrapped = ClientConnectionRequestFactory .wrap(noop); assertTrue(wrapped instanceof Wrapped); }
@Test(expected = IllegalArgumentException.class) public void wrapTwice() { ConnectionRequest wrapped = ClientConnectionRequestFactory.wrap(noop); ClientConnectionRequestFactory.wrap(wrapped); }