Add run method to EnsureCalledOnce and EnsureCalledOnceWithParam to ensure that assertSuccess is always called.

This commit is contained in:
Benoit Marty 2024-01-08 09:55:22 +01:00
parent dee8008917
commit 2c667a0dc0
2 changed files with 47 additions and 37 deletions

View file

@ -27,6 +27,11 @@ class EnsureCalledOnce : () -> Unit {
throw AssertionError("Expected to be called once, but was called $counter times")
}
}
fun run(block: (callback: EnsureCalledOnce) -> Unit) {
block(this)
assertSuccess()
}
}
class EnsureCalledOnceWithParam<T>(
@ -45,4 +50,9 @@ class EnsureCalledOnceWithParam<T>(
throw AssertionError("Expected to be called once, but was called $counter times")
}
}
fun run(block: (callback: EnsureCalledOnceWithParam<T>) -> Unit) {
block(this)
assertSuccess()
}
}