public class P6WrapperUnwrapDelegateTest extends BaseTestCase {
@Test
public void testCastableFromProxy() throws SQLException {
Connection con = new TestConnectionImpl();
Connection proxy = ProxyFactory.createProxy(con, new GenericInvocationHandler<Connection>(con));
// if the proxy implements the interface then the proxy should be returned
{
Connection unwrapped = proxy.unwrap(Connection.class);
assertTrue(ProxyFactory.isProxy(unwrapped));
}
{
TestConnection unwrapped = proxy.unwrap(TestConnection.class);
assertTrue(ProxyFactory.isProxy(unwrapped));
}
{
Wrapper unwrapped = proxy.unwrap(Wrapper.class);
assertTrue(ProxyFactory.isProxy(unwrapped));
}
{
AutoCloseable unwrapped = proxy.unwrap(AutoCloseable.class);
assertTrue(ProxyFactory.isProxy(unwrapped));
}
// TestConnectionImpl is not implemented by the proxy - proxy will not be returned
{
TestConnectionImpl unwrapped = proxy.unwrap(TestConnectionImpl.class);
assertFalse(ProxyFactory.isProxy(unwrapped));
}
}