### Question:
Datasets { public static Collection<URI> list(URI uri) { boolean isRepo = URIBuilder.REPO_SCHEME.equals(uri.getScheme()); Preconditions.checkArgument(isRepo, "Not a repository URI: " + uri); DatasetRepository repo = Registration .open(URI.create(uri.getRawSchemeSpecificPart())); URI repoUri = repo.getUri(); List<URI> datasets = Lists.newArrayList(); for (String namespace : repo.namespaces()) { for (String dataset : repo.datasets(namespace)) { datasets.add(new URIBuilder(repoUri, namespace, dataset).build()); } } return datasets; }  @SuppressWarnings("unchecked") static V load(URI uri, Class<E> type); @SuppressWarnings("unchecked") static V load(URI uri); static V load(String uriString, Class<E> type); static V load(String uriString); @SuppressWarnings("unchecked") static V create(URI uri, DatasetDescriptor descriptor, Class<E> type); @SuppressWarnings("unchecked") static V create(URI uri, DatasetDescriptor descriptor); static V create(String uri, DatasetDescriptor descriptor, Class<E> type); @SuppressWarnings("unchecked") static V create(String uri, DatasetDescriptor descriptor); @SuppressWarnings("unchecked") static D update(
      URI uri, DatasetDescriptor descriptor, Class<E> type); @SuppressWarnings("unchecked") static D update(
      URI uri, DatasetDescriptor descriptor); static D update(String uri, DatasetDescriptor descriptor, Class<E> type); static D update(String uri, DatasetDescriptor descriptor); static boolean delete(URI uri); static boolean delete(String uri); static boolean moveToTrash(URI uri); static boolean moveToTrash(String uri); static boolean exists(URI uri); static boolean exists(String uri); static Collection<URI> list(URI uri); static Collection<URI> list(String uri);  }### Answer:
@Test public void testListRejectsDatasetUri() { TestHelpers.assertThrows("Should reject dataset URI", IllegalArgumentException.class, new Runnable() { @Override public void run() { Datasets.list(new URIBuilder(repoUri, "ns", "test").build()); } }); verifyNoMoreInteractions(repo); }
@Test public void testListRejectsViewUri() { TestHelpers.assertThrows("Should reject dataset URI", IllegalArgumentException.class, new Runnable() { @Override public void run() { Datasets.list(new URIBuilder(repoUri, "ns", "test") .with("field", 34) .build()); } }); verifyNoMoreInteractions(repo); }
@Test public void testListRepoUri() { when(repo.namespaces()).thenReturn(Lists.newArrayList("ns")); when(repo.datasets("ns")).thenReturn(Lists.newArrayList("a", "b", "c")); List<URI> expected = Lists.newArrayList( new URIBuilder(repoUri, "ns", "a").build(), new URIBuilder(repoUri, "ns", "b").build(), new URIBuilder(repoUri, "ns", "c").build() ); Collection<URI> datasetUris = Datasets.list(repoUri); verify(repo, times(2)).getUri(); verify(repo).namespaces(); verify(repo).datasets("ns"); verifyNoMoreInteractions(repo); Assert.assertEquals(expected, datasetUris); }
@Test public void testListStringRepoUri() { when(repo.namespaces()).thenReturn(Lists.newArrayList("ns")); when(repo.datasets("ns")).thenReturn(Lists.newArrayList("a", "b", "c")); List<URI> expected = Lists.newArrayList( new URIBuilder(repoUri, "ns", "a").build(), new URIBuilder(repoUri, "ns", "b").build(), new URIBuilder(repoUri, "ns", "c").build() ); Collection<URI> datasetUris = Datasets.list(repoUri.toString()); verify(repo, times(2)).getUri(); verify(repo).namespaces(); verify(repo).datasets("ns"); verifyNoMoreInteractions(repo); Assert.assertEquals(expected, datasetUris); }