DefaultStorageAccessor implements StorageAccessor { @Override public <T> T unwrap(Class<T> cls) { if (cls.isAssignableFrom(getClass())) { return cls.cast(this); } else if (cls.isAssignableFrom(dataSource.getClass())) { return cls.cast(dataSource); } throw new OWLPersistenceException("Instance of class " + cls + " not found."); } DefaultStorageAccessor(OntologyStorageProperties storageProperties, Map<String, String> properties); @Override Connection acquireConnection(); @Override void close(); @Override boolean isOpen(); @Override T unwrap(Class<T> cls);  }
@Test void unwrapReturnsMatchingDataSourceInstance() { final DefaultStorageAccessor a = new DefaultStorageAccessor(storageProperties(DATA_SOURCE_CLASS), Collections.emptyMap()); final DataSourceStub ds = a.unwrap(DataSourceStub.class); assertNotNull(ds); }
@Test void unwrapThrowsExceptionWhenNoMatchingInstanceIsFound() { final DefaultStorageAccessor a = new DefaultStorageAccessor(storageProperties(DATA_SOURCE_CLASS), Collections.emptyMap()); final OWLPersistenceException ex = assertThrows(OWLPersistenceException.class, () -> a.unwrap(String.class)); assertEquals("Instance of class " + String.class + " not found.", ex.getMessage()); }