protected NodeSequence allNodes( float score, int sizeOfBatches ) { return multipleBatchesOf(cache.getAllNodeKeys(), score, sizeOfBatches); }
addNodeWithLeafChildren("node33", "node331", "node332", "node333"); when(cache.getAllNodeKeys()).thenAnswer(new Answer<Iterator<NodeKey>>() { @Override public Iterator<NodeKey> answer( InvocationOnMock invocation ) throws Throwable {
@Test public void shouldIterateOverAllNodeKeysInTheCacheWhenUsingHasNextAndNext() { Set<NodeKey> expected = new HashSet<NodeKey>(allKeys); Iterator<NodeKey> iter = cache.getAllNodeKeys(); while (iter.hasNext()) { NodeKey key = iter.next(); assertThat(key, is(notNullValue())); assertThat(expected.remove(key), is(true)); } assertThat(expected.isEmpty(), is(true)); }
protected NodeSequence allNodes( float score ) { return NodeSequence.withNodeKeys(cache.getAllNodeKeys(), -1, score, workspaceName(), cache); }
@Test public void shouldIterateOverAllNodeKeysInTheCacheWhenUsingOnlyNext() { Set<NodeKey> expected = new HashSet<NodeKey>(allKeys); Iterator<NodeKey> iter = cache.getAllNodeKeys(); for (int i = 0; i != allKeys.size(); ++i) { NodeKey key = iter.next(); assertThat(key, is(notNullValue())); assertThat(expected.remove(key), is(true)); } assertThat(expected.isEmpty(), is(true)); try { iter.next(); fail("Should have thrown a NoSuchElementException"); } catch (NoSuchElementException e) { // expected } }