Remove internal modifiers from test classes/methods
This commit is contained in:
parent
f2c0f5be32
commit
63da9642fb
@ -4,12 +4,12 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertSame
|
import kotlin.test.assertSame
|
||||||
|
|
||||||
internal class AndTest {
|
class AndTest {
|
||||||
private object AndError
|
private object AndError
|
||||||
|
|
||||||
internal class `and` {
|
class And {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 500,
|
expected = 500,
|
||||||
actual = Ok(230).and { Ok(500) }.get()
|
actual = Ok(230).and { Ok(500) }.get()
|
||||||
@ -17,7 +17,7 @@ internal class AndTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfErr() {
|
fun returnsValueIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "hello world",
|
expected = "hello world",
|
||||||
actual = Ok(300).and { Err("hello world") }.getError()
|
actual = Ok(300).and { Err("hello world") }.getError()
|
||||||
@ -25,9 +25,9 @@ internal class AndTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `andThen` {
|
class AndThen {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTransformedValueIfOk() {
|
fun returnsTransformedValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 12,
|
expected = 12,
|
||||||
actual = Ok(5).andThen { Ok(it + 7) }.get()
|
actual = Ok(5).andThen { Ok(it + 7) }.get()
|
||||||
@ -35,7 +35,7 @@ internal class AndTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
assertSame(
|
assertSame(
|
||||||
expected = AndError,
|
expected = AndError,
|
||||||
actual = Ok(20).andThen { Ok(it + 43) }.andThen { Err(AndError) }.getError()!!
|
actual = Ok(20).andThen { Ok(it + 43) }.andThen { Err(AndError) }.getError()!!
|
||||||
|
@ -4,10 +4,10 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
internal class GetTest {
|
class GetTest {
|
||||||
internal class `get` {
|
class Get {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 12,
|
expected = 12,
|
||||||
actual = Ok(12).get()
|
actual = Ok(12).get()
|
||||||
@ -15,19 +15,19 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsNullIfErr() {
|
fun returnsNullIfErr() {
|
||||||
assertNull(Err("error").get())
|
assertNull(Err("error").get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `getError` {
|
class GetError {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsNullIfOk() {
|
fun returnsNullIfOk() {
|
||||||
assertNull(Ok("example").getError())
|
assertNull(Ok("example").getError())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "example",
|
expected = "example",
|
||||||
actual = Err("example").getError()
|
actual = Err("example").getError()
|
||||||
@ -35,9 +35,9 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `getOr` {
|
class GetOr {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "hello",
|
expected = "hello",
|
||||||
actual = Ok("hello").getOr { "world" }
|
actual = Ok("hello").getOr { "world" }
|
||||||
@ -45,7 +45,7 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsDefaultValueIfErr() {
|
fun returnsDefaultValueIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "default",
|
expected = "default",
|
||||||
actual = Err("error").getOr { "default" }
|
actual = Err("error").getOr { "default" }
|
||||||
@ -53,9 +53,9 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `getErrorOr` {
|
class GetErrorOr {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsDefaultValueIfOk() {
|
fun returnsDefaultValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "world",
|
expected = "world",
|
||||||
actual = Ok("hello").getErrorOr { "world" }
|
actual = Ok("hello").getErrorOr { "world" }
|
||||||
@ -63,7 +63,7 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "hello",
|
expected = "hello",
|
||||||
actual = Err("hello").getErrorOr { "world" }
|
actual = Err("hello").getErrorOr { "world" }
|
||||||
@ -71,9 +71,9 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `getOrElse` {
|
class GetOrElse {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "hello",
|
expected = "hello",
|
||||||
actual = Ok("hello").getOrElse { "world" }
|
actual = Ok("hello").getOrElse { "world" }
|
||||||
@ -81,7 +81,7 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTransformedErrorIfErr() {
|
fun returnsTransformedErrorIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "world",
|
expected = "world",
|
||||||
actual = Err("hello").getOrElse { "world" }
|
actual = Err("hello").getOrElse { "world" }
|
||||||
@ -89,9 +89,9 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `getErrorOrElse` {
|
class GetErrorOrElse {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTransformedValueIfOk() {
|
fun returnsTransformedValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "world",
|
expected = "world",
|
||||||
actual = Ok("hello").getErrorOrElse { "world" }
|
actual = Ok("hello").getErrorOrElse { "world" }
|
||||||
@ -99,7 +99,7 @@ internal class GetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "hello",
|
expected = "hello",
|
||||||
actual = Err("hello").getErrorOrElse { "world" }
|
actual = Err("hello").getErrorOrElse { "world" }
|
||||||
|
@ -4,15 +4,15 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertSame
|
import kotlin.test.assertSame
|
||||||
|
|
||||||
internal class IterableTest {
|
class IterableTest {
|
||||||
private sealed class IterableError {
|
private sealed class IterableError {
|
||||||
object IterableError1 : IterableError()
|
object IterableError1 : IterableError()
|
||||||
object IterableError2 : IterableError()
|
object IterableError2 : IterableError()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `fold` {
|
class Fold {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnAccumulatedValueIfOk() {
|
fun returnAccumulatedValueIfOk() {
|
||||||
val result = listOf(20, 30, 40, 50).fold(
|
val result = listOf(20, 30, 40, 50).fold(
|
||||||
initial = 10,
|
initial = 10,
|
||||||
operation = { a, b -> Ok(a + b) }
|
operation = { a, b -> Ok(a + b) }
|
||||||
@ -27,7 +27,7 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsFirstErrorIfErr() {
|
fun returnsFirstErrorIfErr() {
|
||||||
val result: Result<Int, IterableError> = listOf(5, 10, 15, 20, 25).fold(
|
val result: Result<Int, IterableError> = listOf(5, 10, 15, 20, 25).fold(
|
||||||
initial = 1,
|
initial = 1,
|
||||||
operation = { a, b ->
|
operation = { a, b ->
|
||||||
@ -48,9 +48,9 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `foldRight` {
|
class FoldRight {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsAccumulatedValueIfOk() {
|
fun returnsAccumulatedValueIfOk() {
|
||||||
val result = listOf(2, 5, 10, 20).foldRight(
|
val result = listOf(2, 5, 10, 20).foldRight(
|
||||||
initial = 100,
|
initial = 100,
|
||||||
operation = { a, b -> Ok(b - a) }
|
operation = { a, b -> Ok(b - a) }
|
||||||
@ -65,7 +65,7 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsLastErrorIfErr() {
|
fun returnsLastErrorIfErr() {
|
||||||
val result = listOf(2, 5, 10, 20, 40).foldRight(
|
val result = listOf(2, 5, 10, 20, 40).foldRight(
|
||||||
initial = 38500,
|
initial = 38500,
|
||||||
operation = { a, b ->
|
operation = { a, b ->
|
||||||
@ -86,9 +86,9 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `combine` {
|
class Combine {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValuesIfAllOk() {
|
fun returnsValuesIfAllOk() {
|
||||||
val values = combine(
|
val values = combine(
|
||||||
Ok(10),
|
Ok(10),
|
||||||
Ok(20),
|
Ok(20),
|
||||||
@ -117,7 +117,7 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsFirstErrorIfErr() {
|
fun returnsFirstErrorIfErr() {
|
||||||
val result = combine(
|
val result = combine(
|
||||||
Ok(20),
|
Ok(20),
|
||||||
Ok(40),
|
Ok(40),
|
||||||
@ -136,9 +136,9 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `getAll` {
|
class GetAll {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsAllValues() {
|
fun returnsAllValues() {
|
||||||
val values = getAll(
|
val values = getAll(
|
||||||
Ok("hello"),
|
Ok("hello"),
|
||||||
Ok("big"),
|
Ok("big"),
|
||||||
@ -175,9 +175,9 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `getAllErrors` {
|
class GetAllErrors {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsAllErrors() {
|
fun returnsAllErrors() {
|
||||||
val errors = getAllErrors(
|
val errors = getAllErrors(
|
||||||
Err(IterableError.IterableError2),
|
Err(IterableError.IterableError2),
|
||||||
Ok("haskell"),
|
Ok("haskell"),
|
||||||
@ -222,9 +222,9 @@ internal class IterableTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `partition` {
|
class Partition {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsPairOfValuesAndErrors() {
|
fun returnsPairOfValuesAndErrors() {
|
||||||
val pairs = partition(
|
val pairs = partition(
|
||||||
Err(IterableError.IterableError2),
|
Err(IterableError.IterableError2),
|
||||||
Ok("haskell"),
|
Ok("haskell"),
|
||||||
|
@ -4,16 +4,16 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertSame
|
import kotlin.test.assertSame
|
||||||
|
|
||||||
internal class MapTest {
|
class MapTest {
|
||||||
private sealed class MapError(val reason: String) {
|
private sealed class MapErr(val reason: String) {
|
||||||
object HelloError : MapError("hello")
|
object HelloError : MapErr("hello")
|
||||||
object WorldError : MapError("world")
|
object WorldError : MapErr("world")
|
||||||
class CustomError(reason: String) : MapError(reason)
|
class CustomError(reason: String) : MapErr(reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `map` {
|
class Map {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTransformedValueIfOk() {
|
fun returnsTransformedValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 30,
|
expected = 30,
|
||||||
actual = Ok(10).map { it + 20 }.get()
|
actual = Ok(10).map { it + 20 }.get()
|
||||||
@ -22,22 +22,22 @@ internal class MapTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("UNREACHABLE_CODE")
|
@Suppress("UNREACHABLE_CODE")
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
val result = Err(MapError.HelloError).map { "hello $it" }
|
val result = Err(MapErr.HelloError).map { "hello $it" }
|
||||||
|
|
||||||
result as Err
|
result as Err
|
||||||
|
|
||||||
assertSame(
|
assertSame(
|
||||||
expected = MapError.HelloError,
|
expected = MapErr.HelloError,
|
||||||
actual = result.error
|
actual = result.error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `mapError` {
|
class MapError {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
val value = Ok(55).map { it + 15 }.mapError { MapError.WorldError }.get()
|
val value = Ok(55).map { it + 15 }.mapError { MapErr.WorldError }.get()
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 70,
|
expected = 70,
|
||||||
@ -46,16 +46,16 @@ internal class MapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
val result: Result<String, MapError> = Ok("let")
|
val result: Result<String, MapErr> = Ok("let")
|
||||||
.map { "$it me" }
|
.map { "$it me" }
|
||||||
.andThen {
|
.andThen {
|
||||||
when (it) {
|
when (it) {
|
||||||
"let me" -> Err(MapError.CustomError("$it $it"))
|
"let me" -> Err(MapErr.CustomError("$it $it"))
|
||||||
else -> Ok("$it get")
|
else -> Ok("$it get")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mapError { MapError.CustomError("${it.reason} get what i want") }
|
.mapError { MapErr.CustomError("${it.reason} get what i want") }
|
||||||
|
|
||||||
result as Err
|
result as Err
|
||||||
|
|
||||||
@ -66,10 +66,10 @@ internal class MapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `mapBoth` {
|
class MapBoth {
|
||||||
@Test
|
@Test
|
||||||
@Suppress("UNREACHABLE_CODE")
|
@Suppress("UNREACHABLE_CODE")
|
||||||
internal fun returnsTransformedValueIfOk() {
|
fun returnsTransformedValueIfOk() {
|
||||||
val value = Ok("there is").mapBoth(
|
val value = Ok("there is").mapBoth(
|
||||||
success = { "$it a light" },
|
success = { "$it a light" },
|
||||||
failure = { "$it that never" }
|
failure = { "$it that never" }
|
||||||
@ -83,8 +83,8 @@ internal class MapTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("UNREACHABLE_CODE")
|
@Suppress("UNREACHABLE_CODE")
|
||||||
internal fun returnsTransformedErrorIfErr() {
|
fun returnsTransformedErrorIfErr() {
|
||||||
val error = Err(MapError.CustomError("this")).mapBoth(
|
val error = Err(MapErr.CustomError("this")).mapBoth(
|
||||||
success = { "$it charming" },
|
success = { "$it charming" },
|
||||||
failure = { "${it.reason} man" }
|
failure = { "${it.reason} man" }
|
||||||
)
|
)
|
||||||
@ -96,13 +96,13 @@ internal class MapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `mapEither` {
|
class MapEither {
|
||||||
@Test
|
@Test
|
||||||
@Suppress("UNREACHABLE_CODE")
|
@Suppress("UNREACHABLE_CODE")
|
||||||
internal fun returnsTransformedValueIfOk() {
|
fun returnsTransformedValueIfOk() {
|
||||||
val result = Ok(500).mapEither(
|
val result = Ok(500).mapEither(
|
||||||
success = { it + 500 },
|
success = { it + 500 },
|
||||||
failure = { MapError.CustomError("$it") }
|
failure = { MapErr.CustomError("$it") }
|
||||||
)
|
)
|
||||||
|
|
||||||
result as Ok
|
result as Ok
|
||||||
@ -114,10 +114,10 @@ internal class MapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTransformedErrorIfErr() {
|
fun returnsTransformedErrorIfErr() {
|
||||||
val result = Err("the reckless").mapEither(
|
val result = Err("the reckless").mapEither(
|
||||||
success = { "the wild youth" },
|
success = { "the wild youth" },
|
||||||
failure = { MapError.CustomError("the truth") }
|
failure = { MapErr.CustomError("the truth") }
|
||||||
)
|
)
|
||||||
|
|
||||||
result as Err
|
result as Err
|
||||||
|
@ -3,13 +3,13 @@ package com.github.michaelbull.result
|
|||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
internal class OnTest {
|
class OnTest {
|
||||||
object CounterError
|
object CounterError
|
||||||
class Counter(var count: Int)
|
class Counter(var count: Int)
|
||||||
|
|
||||||
internal class `onSuccess` {
|
class OnSuccess {
|
||||||
@Test
|
@Test
|
||||||
internal fun invokesActionIfOk() {
|
fun invokesActionIfOk() {
|
||||||
val counter = Counter(50)
|
val counter = Counter(50)
|
||||||
|
|
||||||
Ok(counter).onSuccess { it.count += 50 }
|
Ok(counter).onSuccess { it.count += 50 }
|
||||||
@ -21,7 +21,7 @@ internal class OnTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun invokesNothingIfErr() {
|
fun invokesNothingIfErr() {
|
||||||
val counter = Counter(200)
|
val counter = Counter(200)
|
||||||
|
|
||||||
Err(CounterError).onSuccess { counter.count -= 50 }
|
Err(CounterError).onSuccess { counter.count -= 50 }
|
||||||
@ -33,9 +33,9 @@ internal class OnTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `onFailure` {
|
class OnFailure {
|
||||||
@Test
|
@Test
|
||||||
internal fun invokesActionIfErr() {
|
fun invokesActionIfErr() {
|
||||||
val counter = Counter(555)
|
val counter = Counter(555)
|
||||||
|
|
||||||
Err(CounterError).onFailure { counter.count += 100 }
|
Err(CounterError).onFailure { counter.count += 100 }
|
||||||
@ -47,7 +47,7 @@ internal class OnTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun invokesNothingIfOk() {
|
fun invokesNothingIfOk() {
|
||||||
val counter = Counter(1020)
|
val counter = Counter(1020)
|
||||||
|
|
||||||
Ok("hello").onFailure { counter.count = 1030 }
|
Ok("hello").onFailure { counter.count = 1030 }
|
||||||
|
@ -3,12 +3,12 @@ package com.github.michaelbull.result
|
|||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
internal class OrTest {
|
class OrTest {
|
||||||
private object OrError
|
private object OrError
|
||||||
|
|
||||||
internal class `or` {
|
class Or {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 500,
|
expected = 500,
|
||||||
actual = Ok(500).or { Ok(1000) }.get()
|
actual = Ok(500).or { Ok(1000) }.get()
|
||||||
@ -16,7 +16,7 @@ internal class OrTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsDefaultValueIfErr() {
|
fun returnsDefaultValueIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 5000,
|
expected = 5000,
|
||||||
actual = Err(OrError).or { Ok(5000) }.get()
|
actual = Err(OrError).or { Ok(5000) }.get()
|
||||||
@ -24,9 +24,9 @@ internal class OrTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `orElse` {
|
class OrElse {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 3000,
|
expected = 3000,
|
||||||
actual = Ok(3000).orElse { Ok(4000) }.get()
|
actual = Ok(3000).orElse { Ok(4000) }.get()
|
||||||
@ -34,7 +34,7 @@ internal class OrTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTransformedValueIfErr() {
|
fun returnsTransformedValueIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 2000,
|
expected = 2000,
|
||||||
actual = Err(4000).orElse { Ok(2000) }.get()
|
actual = Err(4000).orElse { Ok(2000) }.get()
|
||||||
@ -42,9 +42,9 @@ internal class OrTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `recover` {
|
class Recover {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 3000,
|
expected = 3000,
|
||||||
actual = Ok(3000).recover { 4000 }.get()
|
actual = Ok(3000).recover { 4000 }.get()
|
||||||
@ -52,7 +52,7 @@ internal class OrTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTransformedValueIfErr() {
|
fun returnsTransformedValueIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 2000,
|
expected = 2000,
|
||||||
actual = Err(4000).recover { 2000 }.get()
|
actual = Err(4000).recover { 2000 }.get()
|
||||||
|
@ -2,31 +2,31 @@ package com.github.michaelbull.result
|
|||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
internal class ResultIteratorTest {
|
class ResultIteratorTest {
|
||||||
internal class `hasNext` {
|
class HasNext {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsTrueIfUnyieldedAndOk() {
|
fun returnsTrueIfUnyieldedAndOk() {
|
||||||
val iterator = Ok("hello").iterator()
|
val iterator = Ok("hello").iterator()
|
||||||
assertTrue { iterator.hasNext() }
|
assertTrue { iterator.hasNext() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsFalseIfErr() {
|
fun returnsFalseIfErr() {
|
||||||
val iterator = Err("hello").iterator()
|
val iterator = Err("hello").iterator()
|
||||||
assertFalse { iterator.hasNext() }
|
assertFalse { iterator.hasNext() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsFalseIfYielded() {
|
fun returnsFalseIfYielded() {
|
||||||
val iterator = Ok("hello").iterator()
|
val iterator = Ok("hello").iterator()
|
||||||
iterator.next()
|
iterator.next()
|
||||||
assertFalse { iterator.hasNext() }
|
assertFalse { iterator.hasNext() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `next` {
|
class Next {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfUnyieldedAndOk() {
|
fun returnsValueIfUnyieldedAndOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "hello",
|
expected = "hello",
|
||||||
actual = Ok("hello").iterator().next()
|
actual = Ok("hello").iterator().next()
|
||||||
@ -34,29 +34,29 @@ internal class ResultIteratorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun throwsExceptionIfUnyieldedAndErr() {
|
fun throwsExceptionIfUnyieldedAndErr() {
|
||||||
val iterator = Err("hello").iterator()
|
val iterator = Err("hello").iterator()
|
||||||
assertFailsWith<NoSuchElementException> { iterator.next() }
|
assertFailsWith<NoSuchElementException> { iterator.next() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun throwsExceptionIfYieldedAndOk() {
|
fun throwsExceptionIfYieldedAndOk() {
|
||||||
val iterator = Ok("hello").iterator()
|
val iterator = Ok("hello").iterator()
|
||||||
iterator.next()
|
iterator.next()
|
||||||
assertFailsWith<NoSuchElementException> { iterator.next() }
|
assertFailsWith<NoSuchElementException> { iterator.next() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `remove` {
|
class Remove {
|
||||||
@Test
|
@Test
|
||||||
internal fun makesHasNextReturnFalse() {
|
fun makesHasNextReturnFalse() {
|
||||||
val iterator = Ok("hello").mutableIterator()
|
val iterator = Ok("hello").mutableIterator()
|
||||||
iterator.remove()
|
iterator.remove()
|
||||||
assertFalse { iterator.hasNext() }
|
assertFalse { iterator.hasNext() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun makesNextThrowException() {
|
fun makesNextThrowException() {
|
||||||
val iterator = Ok("hello").mutableIterator()
|
val iterator = Ok("hello").mutableIterator()
|
||||||
iterator.remove()
|
iterator.remove()
|
||||||
assertFailsWith<NoSuchElementException> { iterator.next() }
|
assertFailsWith<NoSuchElementException> { iterator.next() }
|
||||||
|
@ -4,10 +4,10 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertSame
|
import kotlin.test.assertSame
|
||||||
|
|
||||||
internal class ResultTest {
|
class ResultTest {
|
||||||
internal class `of` {
|
class Of {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsOkIfInvocationSuccessful() {
|
fun returnsOkIfInvocationSuccessful() {
|
||||||
val callback = { "example" }
|
val callback = { "example" }
|
||||||
val result = Result.of(callback)
|
val result = Result.of(callback)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ internal class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrIfInvocationFails() {
|
fun returnsErrIfInvocationFails() {
|
||||||
val exception = IllegalArgumentException("throw me")
|
val exception = IllegalArgumentException("throw me")
|
||||||
val callback = { throw exception }
|
val callback = { throw exception }
|
||||||
val result = Result.of(callback)
|
val result = Result.of(callback)
|
||||||
@ -30,9 +30,9 @@ internal class ResultTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `toResultOr` {
|
class ToResultOr {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsOkfIfNonNull() {
|
fun returnsOkfIfNonNull() {
|
||||||
val result = "ok".toResultOr { "err" }
|
val result = "ok".toResultOr { "err" }
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@ -42,7 +42,7 @@ internal class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrIfNull() {
|
fun returnsErrIfNull() {
|
||||||
val result = "ok".toLongOrNull().toResultOr { "err" }
|
val result = "ok".toLongOrNull().toResultOr { "err" }
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
@ -4,10 +4,10 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
internal class UnwrapTest {
|
class UnwrapTest {
|
||||||
internal class `unwrap` {
|
class Unwrap {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 5000,
|
expected = 5000,
|
||||||
actual = Ok(5000).unwrap()
|
actual = Ok(5000).unwrap()
|
||||||
@ -15,16 +15,16 @@ internal class UnwrapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun throwsExceptionIfErr() {
|
fun throwsExceptionIfErr() {
|
||||||
assertFailsWith<UnwrapException>("called Result.wrap on an Err value 5000") {
|
assertFailsWith<UnwrapException>("called Result.wrap on an Err value 5000") {
|
||||||
Err(5000).unwrap()
|
Err(5000).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `expect` {
|
class Expect {
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsValueIfOk() {
|
fun returnsValueIfOk() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 1994,
|
expected = 1994,
|
||||||
actual = Ok(1994).expect { "the year should be" }
|
actual = Ok(1994).expect { "the year should be" }
|
||||||
@ -32,7 +32,7 @@ internal class UnwrapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun throwsExceptionIfErr() {
|
fun throwsExceptionIfErr() {
|
||||||
val message = object {
|
val message = object {
|
||||||
override fun toString() = "the year should be"
|
override fun toString() = "the year should be"
|
||||||
}
|
}
|
||||||
@ -43,16 +43,16 @@ internal class UnwrapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `unwrapError` {
|
class UnwrapError {
|
||||||
@Test
|
@Test
|
||||||
internal fun throwsExceptionIfOk() {
|
fun throwsExceptionIfOk() {
|
||||||
assertFailsWith<UnwrapException>("called Result.unwrapError on an Ok value example") {
|
assertFailsWith<UnwrapException>("called Result.unwrapError on an Ok value example") {
|
||||||
Ok("example").unwrapError()
|
Ok("example").unwrapError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = "example",
|
expected = "example",
|
||||||
actual = Err("example").unwrapError()
|
actual = Err("example").unwrapError()
|
||||||
@ -60,9 +60,9 @@ internal class UnwrapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class `expectError` {
|
class ExpectError {
|
||||||
@Test
|
@Test
|
||||||
internal fun throwsExceptionIfOk() {
|
fun throwsExceptionIfOk() {
|
||||||
val message = object {
|
val message = object {
|
||||||
override fun toString() = "the year should be"
|
override fun toString() = "the year should be"
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ internal class UnwrapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun returnsErrorIfErr() {
|
fun returnsErrorIfErr() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 2010,
|
expected = 2010,
|
||||||
actual = Err(2010).expectError { "the year should be" }
|
actual = Err(2010).expectError { "the year should be" }
|
||||||
|
Loading…
Reference in New Issue
Block a user