JenaConnection implements Connection { @Override public <T> T unwrap(Class<T> cls) throws OntoDriverException { ensureOpen(); Objects.requireNonNull(cls); if (cls.isAssignableFrom(getClass())) { return cls.cast(this); } return adapter.unwrap(cls); } JenaConnection(JenaAdapter adapter); @Override boolean isOpen(); @Override void commit(); @Override void rollback(); @Override void setAutoCommit(boolean autoCommit); @Override boolean isAutoCommit(); @Override JenaStatement createStatement(); @Override PreparedStatement prepareStatement(String sparql); @Override boolean isConsistent(URI context); @Override List<URI> getContexts(); @Override boolean contains(Axiom<?> axiom, URI context); @Override Collection<Axiom<?>> find(AxiomDescriptor descriptor); @Override void persist(AxiomValueDescriptor descriptor); @Override URI generateIdentifier(URI classUri); @Override void update(AxiomValueDescriptor descriptor); @Override void remove(AxiomDescriptor descriptor); @Override JenaLists lists(); @Override JenaTypes types(); @Override JenaProperties properties(); @Override T unwrap(Class<T> cls); @Override void close();  }
@Test public void unwrapReturnsConnectionInstanceIfClassMatches() throws Exception { final JenaConnection result = connection.unwrap(JenaConnection.class); assertSame(connection, result); }
@Test public void unwrapPassesCallToAdapterWhenClassDoesNotMatch() throws Exception { connection.unwrap(StorageConnector.class); verify(adapterMock).unwrap(StorageConnector.class); }