@Test public void unwrapForSmartDataSource() throws Exception { ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(new DataSourceStub()); assertTrue(tested.isWrapperFor(DataSource.class)); assertEquals(tested, tested.unwrap(DataSource.class)); assertTrue(tested.isWrapperFor(SmartDataSource.class)); assertEquals(tested, tested.unwrap(SmartDataSource.class)); }
@Test public void unwrapForSupportedInterface() throws Exception { DataSourceStub ds = new DataSourceStub(); ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(ds); assertTrue(tested.isWrapperFor(Supported.class)); assertEquals(ds, tested.unwrap(Supported.class)); }
@Test public void unwrapForUnsupportedInterface() throws Exception { ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(new DataSourceStub()); assertFalse(tested.isWrapperFor(Unsupported.class)); try { tested.unwrap(Unsupported.class); fail(); } catch (SQLException expected) { // this would be the correct behavior in a Java6-only recursive implementation // assertEquals(DataSourceStub.UNWRAP_ERROR_MESSAGE, expected.getMessage()); assertEquals("Unsupported class " + Unsupported.class.getSimpleName(), expected.getMessage()); } }