Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix: cached value in getNext() with limit() fixed
- Loading branch information
Andrey Komarov (k0m@)
committed
Jul 3, 2021
1 parent
1e2b80e
commit 592cadb
Showing
2 changed files
with
59 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/pw/komarov/streamer/CachedAfterLimitBugFixTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pw.komarov.streamer; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class CachedAfterLimitBugFixTests { | ||
private final StringBuilder sb = new StringBuilder(); | ||
private final AtomicInteger ai = new AtomicInteger(); | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
sb.delete(0, sb.length()); | ||
ai.set(0); | ||
} | ||
|
||
@Test | ||
void test1() { | ||
Streamer.generate(ai::getAndIncrement).limit(10).forEach((v) -> sb.append(v).append(" ")); | ||
sb.append(ai.get()); | ||
assertEquals("0 1 2 3 4 5 6 7 8 9 10", sb.toString()); | ||
} | ||
|
||
@Test | ||
void test2() { | ||
Streamer.generate(ai::getAndIncrement).limit(10).distinct().filter(i -> i != 5).limit(8).limit(16).forEach((v) -> sb.append(v).append(" ")); | ||
sb.append(ai.get()); | ||
assertEquals("0 1 2 3 4 6 7 8 9", sb.toString()); | ||
} | ||
} |