SesameDataSource implements DataSource { public synchronized void setRepository(Repository repository) throws SesameDriverException { ensureOpen(); ensureConnected(); try { driver.setRepository(repository); } catch (IllegalArgumentException | IllegalStateException e) { throw new SesameDriverException(e); } }  @Override synchronized void close(); @Override boolean isOpen(); @Override synchronized Connection getConnection(); @Override void setStorageProperties(OntologyStorageProperties storageProperties); @Override void setProperties(Map<String, String> properties); synchronized void setRepository(Repository repository);  }
@Test public void setRepositorySetsUnderlyingRepository() throws Exception { Field connected = dataSource.getClass().getDeclaredField("connected"); connected.setAccessible(true); connected.set(dataSource, true); final Repository repo = new SailRepository(new MemoryStore()); repo.initialize(); try { dataSource.setRepository(repo); verify(driverMock).setRepository(repo); } finally { repo.shutDown(); } }
@Test public void setRepositoryWrapsIllegalStateExceptionIntoSesameDriverException() throws Exception { Field connected = dataSource.getClass().getDeclaredField("connected"); connected.setAccessible(true); connected.set(dataSource, true); doThrow(new IllegalStateException()).when(driverMock).setRepository(any()); thrown.expect(SesameDriverException.class); thrown.expectCause(CoreMatchers.isA(IllegalStateException.class)); dataSource.setRepository(null); }