Guest User

Untitled

a guest
Mar 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. @Test
  2. public void aa() {
  3. Collection<String> fruits;
  4. Iterator<String> fruitIterator;
  5.  
  6. fruitIterator = mock(Iterator.class);
  7. when(fruitIterator.hasNext()).thenReturn(true, true, true, false);
  8. when(fruitIterator.next()).thenReturn("Apple")
  9. .thenReturn("Banana").thenReturn("Pear");
  10.  
  11. fruits = mock(Collection.class);
  12. when(fruits.iterator()).thenReturn(fruitIterator);
  13.  
  14. // this doesn't work (it doesn't print anything)
  15. fruits.forEach(f -> System.out.println(f));
  16.  
  17. // this works fine
  18. /*
  19. int iterations = 0;
  20. for (String fruit : fruits) {
  21. System.out.println(fruit);
  22. }
  23. */
  24. }
Add Comment
Please, Sign In to add comment