public Iterator<SubgraphNode> iterator() { final Iterator<Location> iter = request.iterator(); return new Iterator<SubgraphNode>() { public boolean hasNext() { return iter.hasNext(); } public SubgraphNode next() { return getNode(iter.next()); } public void remove() { throw new UnsupportedOperationException(); } }; }
@Test public void shouldIterateOverNodesInBranchOfDepthOne() { request = new ReadBranchRequest(location("/a"), workspace1, 1); request.setActualLocationOfNode(request.at()); request.setChildren(location("/a"), location("/a/b"), location("/a/c")); Iterator<Location> actual = request.iterator(); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a"))); assertThat(actual.hasNext(), is(false)); }
@Test public void shouldIterateOverNodesInBranchOfDepthTwo() { request = new ReadBranchRequest(location("/a"), workspace1, 2); request.setActualLocationOfNode(request.at()); request.setChildren(location("/a"), location("/a/b"), location("/a/c"), location("/a/d")); request.setChildren(location("/a/b"), location("/a/b/j"), location("/a/b/k")); request.setChildren(location("/a/c"), location("/a/c/j"), location("/a/c/k")); request.setChildren(location("/a/d")); Iterator<Location> actual = request.iterator(); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a"))); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a/b"))); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a/c"))); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a/d"))); assertThat(actual.hasNext(), is(false)); }
request.setChildren(location("/a/b/k")); request.setChildren(location("/a/d")); Iterator<Location> actual = request.iterator(); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a")));