コード例 #1
0
  @Test
  public void shouldHandleSingleItemIterators() throws Exception {
    // Given
    ResourceIterator<Long> it1 = asResourceIterator(iterator(1l));
    ResourceIterator<Long> it2 = asResourceIterator(iterator(5l, 6l, 7l));
    CombiningResourceIterator<Long> combingIterator =
        new CombiningResourceIterator<>(iterator(it1, it2));

    // When I iterate through it, things come back in the right order
    assertThat(IteratorUtil.asList(combingIterator), equalTo(asList(1l, 5l, 6l, 7l)));
  }
コード例 #2
0
  @Test
  public void shouldNotCloseDuringIteration() throws Exception {
    // Given
    ResourceIterator<Long> it1 = spy(asResourceIterator(iterator(1l, 2l, 3l)));
    ResourceIterator<Long> it2 = spy(asResourceIterator(iterator(5l, 6l, 7l)));
    CombiningResourceIterator<Long> combingIterator =
        new CombiningResourceIterator<>(iterator(it1, it2));

    // When I iterate through it, things come back in the right order
    assertThat(IteratorUtil.asList(combingIterator), equalTo(asList(1l, 2l, 3l, 5l, 6l, 7l)));

    // Then
    verify(it1, never()).close();
    verify(it2, never()).close();
  }