All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.kodein.mock.VerificationBuilder.kt Maven / Gradle / Ivy

The newest version!
package org.kodein.mock

import kotlin.jvm.JvmName


public class VerificationBuilder internal constructor(references: References) : ArgConstraintsBuilder(references) {

    @JvmName("threwAny")
    public inline fun threw(block: () -> Unit): Throwable = threw(block)

    public inline fun  threw(block: () -> Unit): E {
        try {
            block()
        } catch (ex: MockerVerificationThrownAssertionError) {
            val cause = ex.cause
            if (cause !is E) throw MockerVerificationLazyAssertionError { "Expected ${E::class.simpleName} exception to be thrown, but was ${cause::class.simpleName}" }
            return cause
        }
        throw MockerVerificationLazyAssertionError { "No exception was thrown" }
    }

    public inline fun  called(block: () -> T): Result = runCatching(block)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy