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
Some assertions should return their parameter back to the caller, to use them as a kind of verification in unit tests.
This will also make chaining assertions possible
theString
.shouldNotBeNull()
.shouldNotBeEmpty()
Example:
infixfun Any?.shouldBeInstanceOf(className:Class<*>) = assertTrue("Expected $this to be an instance of $className", className.isInstance(this))
to
inlinefun <reifiedT: Any> Any.shouldBeInstanceOf() : T=if(this::class.isInstance(T::class)) thisasTelsethrowAssertionError("Expected $this to be an instance of ${T::class.qualifiedName}")
which has to be a separate method to not break existing code.
This would allow:
openclassBase {
fundoSomething() =println("Base")
}
classChild : Base() {
fundifferent() =println("Child")
}
funmain(args:Array<String>) {
val base :Base=Child()
// base.different() - Doesn't compile, not of type Childval child = base.shouldBeInstanceOf<Child>()
child.different()
}
Currently identified assertions:
shouldBeInstanceOf
All numerical assertions in form of: shouldBeGreaterThan
All String and CharSequence assertions
The generic should method
The text was updated successfully, but these errors were encountered:
(came up in #90)
Some assertions should return their parameter back to the caller, to use them as a kind of verification in unit tests.
This will also make chaining assertions possible
Example:
to
which has to be a separate method to not break existing code.
This would allow:
Currently identified assertions:
shouldBeInstanceOf
All numerical assertions in form of:
shouldBeGreaterThan
All String and CharSequence assertions
The generic
should
methodThe text was updated successfully, but these errors were encountered: