Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void aa() {
- Collection<String> fruits;
- Iterator<String> fruitIterator;
- fruitIterator = mock(Iterator.class);
- when(fruitIterator.hasNext()).thenReturn(true, true, true, false);
- when(fruitIterator.next()).thenReturn("Apple")
- .thenReturn("Banana").thenReturn("Pear");
- fruits = mock(Collection.class);
- when(fruits.iterator()).thenReturn(fruitIterator);
- // this doesn't work (it doesn't print anything)
- fruits.forEach(f -> System.out.println(f));
- // this works fine
- /*
- int iterations = 0;
- for (String fruit : fruits) {
- System.out.println(fruit);
- }
- */
- }
Add Comment
Please, Sign In to add comment