24 lines
655 B
Kotlin
24 lines
655 B
Kotlin
package studio.daybreak.mail
|
|
|
|
import java.io.ByteArrayInputStream
|
|
import org.junit.Assert.assertArrayEquals
|
|
import org.junit.Assert.assertEquals
|
|
import org.junit.Test
|
|
|
|
class BoundedInputReaderTest {
|
|
@Test
|
|
fun readsOnlyUpToTheRequestedLimit() {
|
|
val input = ByteArrayInputStream(byteArrayOf(1, 2, 3, 4, 5))
|
|
assertArrayEquals(byteArrayOf(1, 2, 3), BoundedInputReader.read(input, 3))
|
|
assertEquals(2, input.available())
|
|
}
|
|
|
|
@Test
|
|
fun readsShortStreamsToEnd() {
|
|
assertArrayEquals(
|
|
byteArrayOf(1, 2),
|
|
BoundedInputReader.read(ByteArrayInputStream(byteArrayOf(1, 2)), 5)
|
|
)
|
|
}
|
|
}
|