2017-10-21 23:59:16 +00:00
|
|
|
package com.github.michaelbull.result
|
2017-10-21 02:51:30 +00:00
|
|
|
|
|
|
|
import com.natpryce.hamkrest.assertion.assertThat
|
|
|
|
import com.natpryce.hamkrest.equalTo
|
|
|
|
import org.junit.jupiter.api.Test
|
|
|
|
|
|
|
|
internal class OrTest {
|
|
|
|
private object OrError
|
|
|
|
|
|
|
|
@Test
|
|
|
|
internal fun `or should return the result value if ok`() {
|
2017-10-22 14:05:02 +00:00
|
|
|
val value = Ok(500).or(Ok(1000)).get()
|
2017-10-21 02:51:30 +00:00
|
|
|
assertThat(value, equalTo(500))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
internal fun `or should return the default value if not ok`() {
|
2017-10-22 15:01:05 +00:00
|
|
|
val value = Err(OrError).or(Ok(5000)).get()
|
2017-10-21 18:04:23 +00:00
|
|
|
assertThat(value, equalTo(5000))
|
2017-10-21 02:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-10-21 15:52:29 +00:00
|
|
|
internal fun `orElse should return the result value if ok`() {
|
2017-10-22 14:05:02 +00:00
|
|
|
val value = Ok(3000).orElse { Ok(4000) }.get()
|
2017-10-21 15:52:29 +00:00
|
|
|
assertThat(value, equalTo(3000))
|
2017-10-21 02:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-10-21 15:52:29 +00:00
|
|
|
internal fun `orElse should return the transformed value if not ok`() {
|
2017-10-22 15:01:05 +00:00
|
|
|
val value = Err(4000).orElse { Ok(2000) }.get()
|
2017-10-21 18:04:23 +00:00
|
|
|
assertThat(value, equalTo(2000))
|
2017-10-21 02:51:30 +00:00
|
|
|
}
|
|
|
|
}
|