@Test public void singletonIteratorYieldOneElementInWindow() { final Iterator<O> iter = Iterations.iterator(O.ONE); final CenteredWindowIterator<List<Optional<O>>, O> win = new CenteredWindowIterator<List<Optional<O>>, O>(iter, 3, LIST_FACTORY); final List<List<Optional<O>>> got = Consumers.all(win); final List<List<Optional<O>>> expected = new ArrayList<List<Optional<O>>>(); expected.add(Arrays.asList(Optional.<O>empty(), Optional.of(O.ONE), Optional.<O>empty())); Assert.assertEquals(expected, got); }
@Test public void windowsAreInOrder() { final Iterator<O> iter = Iterations.iterator(O.ONE, O.ANOTHER, O.YET_ANOTHER); final CenteredWindowIterator<List<Optional<O>>, O> win = new CenteredWindowIterator<List<Optional<O>>, O>(iter, 3, LIST_FACTORY); final List<List<Optional<O>>> got = Consumers.all(win); final List<List<Optional<O>>> expected = new ArrayList<List<Optional<O>>>(); expected.add(Arrays.asList(Optional.<O>empty(), Optional.of(O.ONE), Optional.of(O.ANOTHER))); expected.add( Arrays.asList(Optional.of(O.ONE), Optional.of(O.ANOTHER), Optional.of(O.YET_ANOTHER))); expected.add( Arrays.asList(Optional.of(O.ANOTHER), Optional.of(O.YET_ANOTHER), Optional.<O>empty())); Assert.assertEquals(expected, got); }