Add unit tests for Result.of

This commit is contained in:
Michael Bull 2017-10-22 15:16:51 +01:00
parent 9960bc78aa
commit 7be628e79e

View File

@ -0,0 +1,25 @@
package com.github.michaelbull.result
import com.natpryce.hamkrest.Matcher
import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.sameInstance
import org.junit.jupiter.api.Test
internal class ResultTest {
@Test
internal fun `of should return ok if invocation did not throw anything`() {
val callback = { "example" }
val value = Result.of(callback).get()
assertThat(value, equalTo("example"))
}
@Test
internal fun `of should return error if invocation threw something`() {
val throwable = IllegalArgumentException("throw me")
val callback = { throw throwable }
val error = Result.of(callback).getError()!!
val matcher: Matcher<Throwable> = sameInstance(throwable)
assertThat(error, matcher)
}
}