You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Allows [InOrder] verification for a single mocked instance: * * mock.inOrder { * verify().foo() * } **/inlinefun <T> T.inOrder(block:InOrderOnType<T>.() ->Any) {
block.invoke(InOrderOnType(this))
}
Which looks really handy but doesn't work if mock is created with default mock behaviour (all methods return null).
That's because of block: InOrderOnType<T>.() -> Any part, which says that block must return something non-null.
Kotlin always adds runtime null-checks at call sites, hence the example code
mock.inOrder {
verify().foo()
}
will always fail with NPE unless mock is configured with when to return something non-null when .foo() is called.
To fix this, the signature of inOrder should be either
Verification.kt contains function:
Which looks really handy but doesn't work if
mock
is created with default mock behaviour (all methods returnnull
).That's because of
block: InOrderOnType<T>.() -> Any
part, which says that block must return something non-null.Kotlin always adds runtime null-checks at call sites, hence the example code
will always fail with NPE unless
mock
is configured withwhen
to return something non-null when.foo()
is called.To fix this, the signature of
inOrder
should be eitheror
Until then the only way of using it is:
mock.inOrder { verify().foo() "hey, inOrder creator messed up, so this line is required to make it work" }
The text was updated successfully, but these errors were encountered: