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

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