JAVA-8924: changes made for adding example of tryAdvance with spiterator (#14208)
* JAVA-8924: changes made for adding example of tryAdvance with spiterator * JAVA-8924: changes made for adding example of tryAdvance with spiterator
This commit is contained in:
parent
5a1906d88c
commit
ecce4a4121
|
@ -1,7 +1,9 @@
|
|||
package com.baeldung.spliteratorAPI;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Spliterator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
|
@ -41,4 +43,13 @@ public class ExecutorUnitTest {
|
|||
assertThat(new Task(split1).call()).containsSequence(Executor.generateElements().size() / 2 + "");
|
||||
assertThat(new Task(split2).call()).containsSequence(Executor.generateElements().size() / 2 + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAstreamOfArticles_whenProcessedInSequentiallyWithSpliterator_ProducessRightOutput() {
|
||||
List<Article> articles = Stream.generate(() -> new Article("Java")).limit(35000).collect(Collectors.toList());
|
||||
Spliterator<Article> spliterator = articles.spliterator();
|
||||
while (spliterator.tryAdvance(article -> article.setName(article.getName().concat("- published by Baeldung"))));
|
||||
|
||||
articles.forEach(article -> assertThat(article.getName()).isEqualTo("Java- published by Baeldung"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue