-
Notifications
You must be signed in to change notification settings - Fork 64
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
Make shouldNotBeNull return non-null instance #90
Comments
Totaly agree, I often encounter this use case too. |
If you want you can review the change before I release it :-) |
This might also be something worth it for almost all other assertions, to return the value on their happy path |
A good candidate would be
to
which has to be a separate method to not break existing code. This would allow: open class Base {
fun doSomething() = println("Base")
}
class Child : Base() {
fun different() = println("Child")
}
fun main(args: Array<String>) {
val base : Base = Child()
// base.different() - Doesn't compile, not of type Child
val child = base.shouldBeInstanceOf<Child>()
child.different()
}``` |
Exactly, it should help wherever possible. Why did you put this as |
Migration to 2.0 is just to keep track of changes that aren't in the 2.0 branch yet. They have to be migrated by hand, because the repository and project structure changes for 2.0. |
I'm tracking the other stuff in #91 to collect most assertions which make sense. I hope to get everything ready and released this weekend :) |
I've just released these changes with v1.34 |
Sometimes you want to test whether a nullable instance is actually null.
Most often I want to run futher tests on this instance afterwards.
It would be nice if the
shouldNotBeNull
fun returned a non null type when the test passes (and throws if not).Sample implementation:
This allows one to write the following code:
Without having to
!!
every user reference.The text was updated successfully, but these errors were encountered: