kotlin-result/src/test/kotlin/com/github/michaelbull/result/AndTest.kt

46 lines
1.1 KiB
Kotlin
Raw Normal View History

2017-10-21 23:59:16 +00:00
package com.github.michaelbull.result
2017-10-21 02:51:30 +00:00
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame
2017-10-21 02:51:30 +00:00
internal class AndTest {
private object AndError
internal class `and` {
@Test
internal fun returnsValueIfOk() {
assertEquals(
expected = 500,
actual = Ok(230).and { Ok(500) }.get()
)
}
@Test
internal fun returnsValueIfErr() {
assertEquals(
expected = "hello world",
actual = Ok(300).and { Err("hello world") }.getError()
)
}
}
internal class `andThen` {
@Test
internal fun returnsTransformedValueIfOk() {
assertEquals(
expected = 12,
actual = Ok(5).andThen { Ok(it + 7) }.get()
)
}
2017-10-21 02:51:30 +00:00
@Test
internal fun returnsErrorIfErr() {
assertSame(
expected = AndError,
actual = Ok(20).andThen { Ok(it + 43) }.andThen { Err(AndError) }.getError()!!
)
}
2017-10-21 02:51:30 +00:00
}
}