-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce assertInstanceOf()
for Kotlin
#3353
Comments
@bjmi Thanks for creating the issue! I think this would be a natural addition. Would you be interested in submitting a PR? |
I can give it a try. |
Resolves junit-team#3353 Signed-off-by: Björn Michael <b.michael@gmx.de>
Resolves junit-team#3353 Signed-off-by: Björn Michael <b.michael@gmx.de>
@mikhail2048 / @bjmi there are two PRs for this now. |
assertInstanceOf()
extension function for Kotlin
It would be great for this implementation to use Kotlin's contracts feature so the instance can be used subsequently as an instance of the expected class. See also: https://youtrack.jetbrains.com/issue/KT-28298 which has been implemented. A slight modification of #3492: inline fun <reified T : Any> assertInstanceOf(actualValue: Any?, message: String? = null): T {
contract {
returns() implies (value is T)
}
return Assertions.assertInstanceOf(T::class.java, actualValue, message)
} will allow this pattern without cast: val bar: Any = foo()
assertInstanceOf<String>(bar)
bar.lowercase() // bar is a String |
@andrewparmet you can leave a suggestion as a review on a PR in context, more likely to get noticed when the PR is reviewed. |
Resolves junit-team#3353 Signed-off-by: Björn Michael <b.michael@gmx.de>
Resolves junit-team#3353 Signed-off-by: Björn Michael <b.michael@gmx.de>
assertInstanceOf()
extension function for KotlinassertInstanceOf()
for Kotlin
This is a follow up of #2492 but for Kotlin.
After discovering the new
assertInstanceOf
assertion (since 5.8) I find it really expressive and useful.Could you please also add a Kotlin variant to Assertions.kt? E.g.
Usage:
Definition:
The text was updated successfully, but these errors were encountered: