Remove internal modifiers from test classes/methods

This commit is contained in:
Michael Bull 2018-11-01 19:02:57 +00:00
parent f2c0f5be32
commit 63da9642fb
9 changed files with 117 additions and 117 deletions

View File

@ -4,12 +4,12 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame
internal class AndTest {
class AndTest {
private object AndError
internal class `and` {
class And {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = 500,
actual = Ok(230).and { Ok(500) }.get()
@ -17,7 +17,7 @@ internal class AndTest {
}
@Test
internal fun returnsValueIfErr() {
fun returnsValueIfErr() {
assertEquals(
expected = "hello world",
actual = Ok(300).and { Err("hello world") }.getError()
@ -25,9 +25,9 @@ internal class AndTest {
}
}
internal class `andThen` {
class AndThen {
@Test
internal fun returnsTransformedValueIfOk() {
fun returnsTransformedValueIfOk() {
assertEquals(
expected = 12,
actual = Ok(5).andThen { Ok(it + 7) }.get()
@ -35,7 +35,7 @@ internal class AndTest {
}
@Test
internal fun returnsErrorIfErr() {
fun returnsErrorIfErr() {
assertSame(
expected = AndError,
actual = Ok(20).andThen { Ok(it + 43) }.andThen { Err(AndError) }.getError()!!

View File

@ -4,10 +4,10 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
internal class GetTest {
internal class `get` {
class GetTest {
class Get {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = 12,
actual = Ok(12).get()
@ -15,19 +15,19 @@ internal class GetTest {
}
@Test
internal fun returnsNullIfErr() {
fun returnsNullIfErr() {
assertNull(Err("error").get())
}
}
internal class `getError` {
class GetError {
@Test
internal fun returnsNullIfOk() {
fun returnsNullIfOk() {
assertNull(Ok("example").getError())
}
@Test
internal fun returnsErrorIfErr() {
fun returnsErrorIfErr() {
assertEquals(
expected = "example",
actual = Err("example").getError()
@ -35,9 +35,9 @@ internal class GetTest {
}
}
internal class `getOr` {
class GetOr {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = "hello",
actual = Ok("hello").getOr { "world" }
@ -45,7 +45,7 @@ internal class GetTest {
}
@Test
internal fun returnsDefaultValueIfErr() {
fun returnsDefaultValueIfErr() {
assertEquals(
expected = "default",
actual = Err("error").getOr { "default" }
@ -53,9 +53,9 @@ internal class GetTest {
}
}
internal class `getErrorOr` {
class GetErrorOr {
@Test
internal fun returnsDefaultValueIfOk() {
fun returnsDefaultValueIfOk() {
assertEquals(
expected = "world",
actual = Ok("hello").getErrorOr { "world" }
@ -63,7 +63,7 @@ internal class GetTest {
}
@Test
internal fun returnsErrorIfErr() {
fun returnsErrorIfErr() {
assertEquals(
expected = "hello",
actual = Err("hello").getErrorOr { "world" }
@ -71,9 +71,9 @@ internal class GetTest {
}
}
internal class `getOrElse` {
class GetOrElse {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = "hello",
actual = Ok("hello").getOrElse { "world" }
@ -81,7 +81,7 @@ internal class GetTest {
}
@Test
internal fun returnsTransformedErrorIfErr() {
fun returnsTransformedErrorIfErr() {
assertEquals(
expected = "world",
actual = Err("hello").getOrElse { "world" }
@ -89,9 +89,9 @@ internal class GetTest {
}
}
internal class `getErrorOrElse` {
class GetErrorOrElse {
@Test
internal fun returnsTransformedValueIfOk() {
fun returnsTransformedValueIfOk() {
assertEquals(
expected = "world",
actual = Ok("hello").getErrorOrElse { "world" }
@ -99,7 +99,7 @@ internal class GetTest {
}
@Test
internal fun returnsErrorIfErr() {
fun returnsErrorIfErr() {
assertEquals(
expected = "hello",
actual = Err("hello").getErrorOrElse { "world" }

View File

@ -4,15 +4,15 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame
internal class IterableTest {
class IterableTest {
private sealed class IterableError {
object IterableError1 : IterableError()
object IterableError2 : IterableError()
}
internal class `fold` {
class Fold {
@Test
internal fun returnAccumulatedValueIfOk() {
fun returnAccumulatedValueIfOk() {
val result = listOf(20, 30, 40, 50).fold(
initial = 10,
operation = { a, b -> Ok(a + b) }
@ -27,7 +27,7 @@ internal class IterableTest {
}
@Test
internal fun returnsFirstErrorIfErr() {
fun returnsFirstErrorIfErr() {
val result: Result<Int, IterableError> = listOf(5, 10, 15, 20, 25).fold(
initial = 1,
operation = { a, b ->
@ -48,9 +48,9 @@ internal class IterableTest {
}
}
internal class `foldRight` {
class FoldRight {
@Test
internal fun returnsAccumulatedValueIfOk() {
fun returnsAccumulatedValueIfOk() {
val result = listOf(2, 5, 10, 20).foldRight(
initial = 100,
operation = { a, b -> Ok(b - a) }
@ -65,7 +65,7 @@ internal class IterableTest {
}
@Test
internal fun returnsLastErrorIfErr() {
fun returnsLastErrorIfErr() {
val result = listOf(2, 5, 10, 20, 40).foldRight(
initial = 38500,
operation = { a, b ->
@ -86,9 +86,9 @@ internal class IterableTest {
}
}
internal class `combine` {
class Combine {
@Test
internal fun returnsValuesIfAllOk() {
fun returnsValuesIfAllOk() {
val values = combine(
Ok(10),
Ok(20),
@ -117,7 +117,7 @@ internal class IterableTest {
}
@Test
internal fun returnsFirstErrorIfErr() {
fun returnsFirstErrorIfErr() {
val result = combine(
Ok(20),
Ok(40),
@ -136,9 +136,9 @@ internal class IterableTest {
}
}
internal class `getAll` {
class GetAll {
@Test
internal fun returnsAllValues() {
fun returnsAllValues() {
val values = getAll(
Ok("hello"),
Ok("big"),
@ -175,9 +175,9 @@ internal class IterableTest {
}
}
internal class `getAllErrors` {
class GetAllErrors {
@Test
internal fun returnsAllErrors() {
fun returnsAllErrors() {
val errors = getAllErrors(
Err(IterableError.IterableError2),
Ok("haskell"),
@ -222,9 +222,9 @@ internal class IterableTest {
}
}
internal class `partition` {
class Partition {
@Test
internal fun returnsPairOfValuesAndErrors() {
fun returnsPairOfValuesAndErrors() {
val pairs = partition(
Err(IterableError.IterableError2),
Ok("haskell"),

View File

@ -4,16 +4,16 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame
internal class MapTest {
private sealed class MapError(val reason: String) {
object HelloError : MapError("hello")
object WorldError : MapError("world")
class CustomError(reason: String) : MapError(reason)
class MapTest {
private sealed class MapErr(val reason: String) {
object HelloError : MapErr("hello")
object WorldError : MapErr("world")
class CustomError(reason: String) : MapErr(reason)
}
internal class `map` {
class Map {
@Test
internal fun returnsTransformedValueIfOk() {
fun returnsTransformedValueIfOk() {
assertEquals(
expected = 30,
actual = Ok(10).map { it + 20 }.get()
@ -22,22 +22,22 @@ internal class MapTest {
@Test
@Suppress("UNREACHABLE_CODE")
internal fun returnsErrorIfErr() {
val result = Err(MapError.HelloError).map { "hello $it" }
fun returnsErrorIfErr() {
val result = Err(MapErr.HelloError).map { "hello $it" }
result as Err
assertSame(
expected = MapError.HelloError,
expected = MapErr.HelloError,
actual = result.error
)
}
}
internal class `mapError` {
class MapError {
@Test
internal fun returnsValueIfOk() {
val value = Ok(55).map { it + 15 }.mapError { MapError.WorldError }.get()
fun returnsValueIfOk() {
val value = Ok(55).map { it + 15 }.mapError { MapErr.WorldError }.get()
assertEquals(
expected = 70,
@ -46,16 +46,16 @@ internal class MapTest {
}
@Test
internal fun returnsErrorIfErr() {
val result: Result<String, MapError> = Ok("let")
fun returnsErrorIfErr() {
val result: Result<String, MapErr> = Ok("let")
.map { "$it me" }
.andThen {
when (it) {
"let me" -> Err(MapError.CustomError("$it $it"))
"let me" -> Err(MapErr.CustomError("$it $it"))
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
@ -66,10 +66,10 @@ internal class MapTest {
}
}
internal class `mapBoth` {
class MapBoth {
@Test
@Suppress("UNREACHABLE_CODE")
internal fun returnsTransformedValueIfOk() {
fun returnsTransformedValueIfOk() {
val value = Ok("there is").mapBoth(
success = { "$it a light" },
failure = { "$it that never" }
@ -83,8 +83,8 @@ internal class MapTest {
@Test
@Suppress("UNREACHABLE_CODE")
internal fun returnsTransformedErrorIfErr() {
val error = Err(MapError.CustomError("this")).mapBoth(
fun returnsTransformedErrorIfErr() {
val error = Err(MapErr.CustomError("this")).mapBoth(
success = { "$it charming" },
failure = { "${it.reason} man" }
)
@ -96,13 +96,13 @@ internal class MapTest {
}
}
internal class `mapEither` {
class MapEither {
@Test
@Suppress("UNREACHABLE_CODE")
internal fun returnsTransformedValueIfOk() {
fun returnsTransformedValueIfOk() {
val result = Ok(500).mapEither(
success = { it + 500 },
failure = { MapError.CustomError("$it") }
failure = { MapErr.CustomError("$it") }
)
result as Ok
@ -114,10 +114,10 @@ internal class MapTest {
}
@Test
internal fun returnsTransformedErrorIfErr() {
fun returnsTransformedErrorIfErr() {
val result = Err("the reckless").mapEither(
success = { "the wild youth" },
failure = { MapError.CustomError("the truth") }
failure = { MapErr.CustomError("the truth") }
)
result as Err

View File

@ -3,13 +3,13 @@ package com.github.michaelbull.result
import kotlin.test.Test
import kotlin.test.assertEquals
internal class OnTest {
class OnTest {
object CounterError
class Counter(var count: Int)
internal class `onSuccess` {
class OnSuccess {
@Test
internal fun invokesActionIfOk() {
fun invokesActionIfOk() {
val counter = Counter(50)
Ok(counter).onSuccess { it.count += 50 }
@ -21,7 +21,7 @@ internal class OnTest {
}
@Test
internal fun invokesNothingIfErr() {
fun invokesNothingIfErr() {
val counter = Counter(200)
Err(CounterError).onSuccess { counter.count -= 50 }
@ -33,9 +33,9 @@ internal class OnTest {
}
}
internal class `onFailure` {
class OnFailure {
@Test
internal fun invokesActionIfErr() {
fun invokesActionIfErr() {
val counter = Counter(555)
Err(CounterError).onFailure { counter.count += 100 }
@ -47,7 +47,7 @@ internal class OnTest {
}
@Test
internal fun invokesNothingIfOk() {
fun invokesNothingIfOk() {
val counter = Counter(1020)
Ok("hello").onFailure { counter.count = 1030 }

View File

@ -3,12 +3,12 @@ package com.github.michaelbull.result
import kotlin.test.Test
import kotlin.test.assertEquals
internal class OrTest {
class OrTest {
private object OrError
internal class `or` {
class Or {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = 500,
actual = Ok(500).or { Ok(1000) }.get()
@ -16,7 +16,7 @@ internal class OrTest {
}
@Test
internal fun returnsDefaultValueIfErr() {
fun returnsDefaultValueIfErr() {
assertEquals(
expected = 5000,
actual = Err(OrError).or { Ok(5000) }.get()
@ -24,9 +24,9 @@ internal class OrTest {
}
}
internal class `orElse` {
class OrElse {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = 3000,
actual = Ok(3000).orElse { Ok(4000) }.get()
@ -34,7 +34,7 @@ internal class OrTest {
}
@Test
internal fun returnsTransformedValueIfErr() {
fun returnsTransformedValueIfErr() {
assertEquals(
expected = 2000,
actual = Err(4000).orElse { Ok(2000) }.get()
@ -42,9 +42,9 @@ internal class OrTest {
}
}
internal class `recover` {
class Recover {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = 3000,
actual = Ok(3000).recover { 4000 }.get()
@ -52,7 +52,7 @@ internal class OrTest {
}
@Test
internal fun returnsTransformedValueIfErr() {
fun returnsTransformedValueIfErr() {
assertEquals(
expected = 2000,
actual = Err(4000).recover { 2000 }.get()

View File

@ -2,31 +2,31 @@ package com.github.michaelbull.result
import kotlin.test.*
internal class ResultIteratorTest {
internal class `hasNext` {
class ResultIteratorTest {
class HasNext {
@Test
internal fun returnsTrueIfUnyieldedAndOk() {
fun returnsTrueIfUnyieldedAndOk() {
val iterator = Ok("hello").iterator()
assertTrue { iterator.hasNext() }
}
@Test
internal fun returnsFalseIfErr() {
fun returnsFalseIfErr() {
val iterator = Err("hello").iterator()
assertFalse { iterator.hasNext() }
}
@Test
internal fun returnsFalseIfYielded() {
fun returnsFalseIfYielded() {
val iterator = Ok("hello").iterator()
iterator.next()
assertFalse { iterator.hasNext() }
}
}
internal class `next` {
class Next {
@Test
internal fun returnsValueIfUnyieldedAndOk() {
fun returnsValueIfUnyieldedAndOk() {
assertEquals(
expected = "hello",
actual = Ok("hello").iterator().next()
@ -34,29 +34,29 @@ internal class ResultIteratorTest {
}
@Test
internal fun throwsExceptionIfUnyieldedAndErr() {
fun throwsExceptionIfUnyieldedAndErr() {
val iterator = Err("hello").iterator()
assertFailsWith<NoSuchElementException> { iterator.next() }
}
@Test
internal fun throwsExceptionIfYieldedAndOk() {
fun throwsExceptionIfYieldedAndOk() {
val iterator = Ok("hello").iterator()
iterator.next()
assertFailsWith<NoSuchElementException> { iterator.next() }
}
}
internal class `remove` {
class Remove {
@Test
internal fun makesHasNextReturnFalse() {
fun makesHasNextReturnFalse() {
val iterator = Ok("hello").mutableIterator()
iterator.remove()
assertFalse { iterator.hasNext() }
}
@Test
internal fun makesNextThrowException() {
fun makesNextThrowException() {
val iterator = Ok("hello").mutableIterator()
iterator.remove()
assertFailsWith<NoSuchElementException> { iterator.next() }

View File

@ -4,10 +4,10 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame
internal class ResultTest {
internal class `of` {
class ResultTest {
class Of {
@Test
internal fun returnsOkIfInvocationSuccessful() {
fun returnsOkIfInvocationSuccessful() {
val callback = { "example" }
val result = Result.of(callback)
@ -18,7 +18,7 @@ internal class ResultTest {
}
@Test
internal fun returnsErrIfInvocationFails() {
fun returnsErrIfInvocationFails() {
val exception = IllegalArgumentException("throw me")
val callback = { throw exception }
val result = Result.of(callback)
@ -30,9 +30,9 @@ internal class ResultTest {
}
}
internal class `toResultOr` {
class ToResultOr {
@Test
internal fun returnsOkfIfNonNull() {
fun returnsOkfIfNonNull() {
val result = "ok".toResultOr { "err" }
assertEquals(
@ -42,7 +42,7 @@ internal class ResultTest {
}
@Test
internal fun returnsErrIfNull() {
fun returnsErrIfNull() {
val result = "ok".toLongOrNull().toResultOr { "err" }
assertEquals(

View File

@ -4,10 +4,10 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
internal class UnwrapTest {
internal class `unwrap` {
class UnwrapTest {
class Unwrap {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = 5000,
actual = Ok(5000).unwrap()
@ -15,16 +15,16 @@ internal class UnwrapTest {
}
@Test
internal fun throwsExceptionIfErr() {
fun throwsExceptionIfErr() {
assertFailsWith<UnwrapException>("called Result.wrap on an Err value 5000") {
Err(5000).unwrap()
}
}
}
internal class `expect` {
class Expect {
@Test
internal fun returnsValueIfOk() {
fun returnsValueIfOk() {
assertEquals(
expected = 1994,
actual = Ok(1994).expect { "the year should be" }
@ -32,7 +32,7 @@ internal class UnwrapTest {
}
@Test
internal fun throwsExceptionIfErr() {
fun throwsExceptionIfErr() {
val message = object {
override fun toString() = "the year should be"
}
@ -43,16 +43,16 @@ internal class UnwrapTest {
}
}
internal class `unwrapError` {
class UnwrapError {
@Test
internal fun throwsExceptionIfOk() {
fun throwsExceptionIfOk() {
assertFailsWith<UnwrapException>("called Result.unwrapError on an Ok value example") {
Ok("example").unwrapError()
}
}
@Test
internal fun returnsErrorIfErr() {
fun returnsErrorIfErr() {
assertEquals(
expected = "example",
actual = Err("example").unwrapError()
@ -60,9 +60,9 @@ internal class UnwrapTest {
}
}
internal class `expectError` {
class ExpectError {
@Test
internal fun throwsExceptionIfOk() {
fun throwsExceptionIfOk() {
val message = object {
override fun toString() = "the year should be"
}
@ -73,7 +73,7 @@ internal class UnwrapTest {
}
@Test
internal fun returnsErrorIfErr() {
fun returnsErrorIfErr() {
assertEquals(
expected = 2010,
actual = Err(2010).expectError { "the year should be" }