File tree Expand file tree Collapse file tree
core-java-modules/core-java-8/src/test/java/com/baeldung/spliteratorAPI Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .baeldung .spliteratorAPI ;
22
33import java .util .Arrays ;
4+ import java .util .List ;
45import java .util .Spliterator ;
6+ import java .util .stream .Collectors ;
57import java .util .stream .Stream ;
68import java .util .stream .StreamSupport ;
79
@@ -41,4 +43,13 @@ public void givenSpliterator_whenAppliedToAListOfArticle_thenSplittedInHalf() {
4143 assertThat (new Task (split1 ).call ()).containsSequence (Executor .generateElements ().size () / 2 + "" );
4244 assertThat (new Task (split2 ).call ()).containsSequence (Executor .generateElements ().size () / 2 + "" );
4345 }
46+
47+ @ Test
48+ public void givenAstreamOfArticles_whenProcessedInSequentiallyWithSpliterator_ProducessRightOutput () {
49+ List <Article > articles = Stream .generate (() -> new Article ("Java" )).limit (35000 ).collect (Collectors .toList ());
50+ Spliterator <Article > spliterator = articles .spliterator ();
51+ while (spliterator .tryAdvance (article -> article .setName (article .getName ().concat ("- published by Baeldung" ))));
52+
53+ articles .forEach (article -> assertThat (article .getName ()).isEqualTo ("Java- published by Baeldung" ));
54+ }
4455}
You can’t perform that action at this time.
0 commit comments