Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jUnit: Migrates PullBasedSpliteratorTest to Kotlin #490

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions src/test/java/sirius/kernel/commons/PullBasedSpliteratorTest.java

This file was deleted.

45 changes: 45 additions & 0 deletions src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt
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())
)
}
}