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

45 lines
1.0 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
2017-10-21 02:51:30 +00:00
internal class OrTest {
private object OrError
internal class `or` {
@Test
internal fun returnsValueIfOk() {
assertEquals(
expected = 500,
actual = Ok(500).or(Ok(1000)).get()
)
}
2017-10-21 02:51:30 +00:00
@Test
internal fun returnsDefaultValueIfErr() {
assertEquals(
expected = 5000,
actual = Err(OrError).or(Ok(5000)).get()
)
}
2017-10-21 02:51:30 +00:00
}
internal class `orElse` {
@Test
internal fun returnsValueIfOk() {
assertEquals(
expected = 3000,
actual = Ok(3000).orElse { Ok(4000) }.get()
)
}
2017-10-21 02:51:30 +00:00
@Test
internal fun returnsTransformedValueIfErr() {
assertEquals(
expected = 2000,
actual = Err(4000).orElse { Ok(2000) }.get()
)
}
2017-10-21 02:51:30 +00:00
}
}