-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from scireum/feature/smo/PullBasedSpliterator…
…Test jUnit: Migrates PullBasedSpliteratorTest to Kotlin
- Loading branch information
Showing
2 changed files
with
45 additions
and
58 deletions.
There are no files selected for viewing
58 changes: 0 additions & 58 deletions
58
src/test/java/sirius/kernel/commons/PullBasedSpliteratorTest.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt
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,45 @@ | ||
/* | ||
* Made with all the love in the world | ||
* by scireum in Remshalden, Germany | ||
* | ||
* Copyright by scireum GmbH | ||
* http://www.scireum.de - info@scireum.de | ||
*/ | ||
package sirius.kernel.commons | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import java.util.* | ||
import java.util.stream.Collectors | ||
import java.util.stream.Stream | ||
import java.util.stream.StreamSupport | ||
|
||
internal class PullBasedSpliteratorTest { | ||
private class TestSpliterator : PullBasedSpliterator<Int?>() { | ||
private var index = 0 | ||
override fun pullNextBlock(): Iterator<Int>? { | ||
if (index < 10) { | ||
val result: MutableList<Int> = ArrayList() | ||
for (i in index until index + 5) { | ||
result.add(i) | ||
} | ||
index += 5 | ||
return result.iterator() | ||
} | ||
return Collections.emptyIterator() | ||
} | ||
|
||
override fun characteristics(): Int { | ||
return 0 | ||
} | ||
} | ||
|
||
@Test | ||
fun streamWorksProperly() { | ||
Assertions.assertEquals(10, StreamSupport.stream(TestSpliterator(), false).count()) | ||
Assertions.assertEquals( | ||
StreamSupport.stream(TestSpliterator(), false).collect(Collectors.toList()), | ||
Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).collect(Collectors.toList()) | ||
) | ||
} | ||
} |