Skip to content

MrBergin/result4k-kotest-matchers

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

Build MavenCentral

result4k-kotest-matchers

Kotest matchers for the Result4k library

Version Matrix

result4k-kotest-matchers forkhandles kotlin java
1.0.0 1.14.0.1 1.6.10 8
2022-09-22 2.2.0.0 1.7.10 17
2022.09.24.1..2022.10.1 2.2.0.0 1.7.10 8
2022.10.2 2.2.0.0 1.7.20 8

Example Gradle usage:

repositories {
    mavenCentral()
}
dependencies {
    testImplementation("dev.mrbergin:result4k-kotest-matchers:2022.10.2")
}

Some example usage:

fun exampleDivideByZero() {
    val result = divide(5, 0)

    //all of these would pass
    result.shouldBeFailure()
    result shouldBeFailure DivideByZeroFailure
    result shouldBeFailure { reason ->
        reason shouldBe DivideByZeroFailure
    }

    //but this will fail with the appropriate message
    result shouldBeSuccess 5 //Throws AssertionError like: Failure(DivideByZero) should be Success(5)
}

object DivideByZeroFailure

fun divide(dividend: Int, divisor: Int): Result<Int, DivideByZeroFailure> {
    return if (divisor == 0) {
        Failure(DivideByZeroFailure)
    } else {
        Success(dividend / divisor)
    }
}