### Question:
DatasetRegistryLocal implements DatasetRegistry { @Override public Dataset datasetFor(String namespace) throws DatasetRegistryException { Dataset dataset; final URI sourceURI = findLastCachedDatasetURI(namespace); dataset = sourceURI == null ? null : new DatasetFactory(new DatasetRegistry() { @Override public Collection<String> findNamespaces() throws DatasetRegistryException { return Collections.singletonList(namespace); } @Override public Dataset datasetFor(String s) throws DatasetRegistryException { Dataset dataset = new DatasetImpl(namespace, sourceURI, getInputStreamFactory()); return new DatasetWithCache(dataset, cacheFactory.cacheFor(dataset)); } }).datasetFor(namespace); if (dataset == null) { throw new DatasetRegistryException("failed to retrieve/cache dataset in namespace [" + namespace + "]"); } return dataset; } DatasetRegistryLocal(String cacheDir, CacheFactory cacheFactory);  DatasetRegistryLocal(String cacheDir, CacheFactory cacheFactory, InputStreamFactory factory); @Override Collection<String> findNamespaces(); @Override Dataset datasetFor(String namespace);  }### Answer:
@Test public void dataset() throws DatasetRegistryException, URISyntaxException { Dataset actual = createDatasetRegistry().datasetFor("globalbioticinteractions/template-dataset"); assertThat(actual, is(notNullValue())); assertThat(actual.getConfigURI(), is(URI.create("/globi.json"))); assertThat(actual.getArchiveURI().toString(), is("https: assertThat(actual.getCitation(), is("Jorrit H. Poelen. 2014. Species associations manually extracted from literature.")); }
@Test public void datasetLocal() throws DatasetRegistryException, URISyntaxException, IOException, NoSuchAlgorithmException { Path testCacheDir = Files.createTempDirectory(Paths.get("target/"), "test"); File localDatasetDir = new File(getClass().getResource("/test-dataset-local/globi.json").toURI()).getParentFile(); File accessFile = createLocalCacheDir(testCacheDir, localDatasetDir); File cacheDir = new File(accessFile.toURI()).getParentFile().getParentFile(); DatasetRegistry registry = new DatasetRegistryLocal(cacheDir.getAbsolutePath(), dataset -> CacheUtil.cacheFor( dataset.getNamespace(), cacheDir.getAbsolutePath(), inStream -> inStream)); Dataset actual = registry.datasetFor("local"); assertThat(actual, is(notNullValue())); assertThat(actual.getConfigURI(), is(URI.create("/globi.json"))); assertThat(actual.getArchiveURI().toString(), is(localDatasetDir.toURI().toString())); assertThat(actual.getCitation(), is("Jorrit H. Poelen. 2014. Species associations manually extracted from literature.")); CacheLocalReadonly readOnlyCache = new CacheLocalReadonly("local", cacheDir.getAbsolutePath(), inStream -> inStream); InputStream inputStream = readOnlyCache.retrieve(URI.create("https: String actualHash = CacheUtil.calculateContentHash(inputStream, new NullOutputStream()); assertThat(actualHash, is("6bfc17b8717e6e8e478552f12404bc8887d691a155ffd9cd9bfc80cb6747c5d2")); }
@Test(expected = DatasetRegistryException.class) public void nonExistingDataset() throws DatasetRegistryException, URISyntaxException { createDatasetRegistry().datasetFor("non/existing"); }