public class MatchersKt
| Modifier and Type | Method and Description |
|---|---|
static Matcher<java.lang.Object> |
beNull()
Matcher that verifies if a reference is null
|
static void |
shouldBeNull(java.lang.Object $receiver)
Verifies that this value is null
|
static void |
shouldBeSameInstanceAs(java.lang.Object $receiver,
java.lang.Object ref) |
static void |
shouldNotBeNull(java.lang.Object $receiver)
Verifies that this is not null
|
static void |
shouldNotBeSameInstanceAs(java.lang.Object $receiver,
java.lang.Object ref) |
public static void shouldBeSameInstanceAs(java.lang.Object $receiver,
java.lang.Object ref)
public static void shouldNotBeSameInstanceAs(java.lang.Object $receiver,
java.lang.Object ref)
public static void shouldBeNull(java.lang.Object $receiver)
Verifies that this value is null
Matcher to verify that a specific value contains a reference to null.
Opposite of MatchersKt.shouldNotBeNull
Example:
val nullable: String? = null
val nonNull: String? = "NonNull"
nullable.shouldBeNull() // Passes
nonNull.shouldBeNull() // Fails
MatchersKt.shouldNotBeNullpublic static void shouldNotBeNull(java.lang.Object $receiver)
Verifies that this is not null
Matcher to verify that a specific nullable reference is not null.
Opposite of MatchersKt.shouldBeNull
Example:
val nullable: String? = null
val nonNull: String? = "NonNull"
nonNull.shouldNotBeNull() // Passes
nullable.shouldNotBeNull() // Fails
Note: This function uses Kotlin Contracts to tell the compiler that this is not null. So after this is used, all subsequent lines can assume the value is not null without having to cast it. For example:
val nonNull: String? = "NonNull"
nonNull.shouldNotBeNull()
useNonNullString(nonNull)
// Notice how this is a not-nullable reference
fun useNonNullString(string: String) { }
MatchersKt.shouldBeNullpublic static Matcher<java.lang.Object> beNull()
Matcher that verifies if a reference is null
Verifies that a given value contains a reference to null or not.
Example:
val nullable: String? = null
val nonNull: String? = "NonNull"
nullable should beNull() // Passes
nonNull should beNull() // Fails
nullable shouldNot beNull() // Fails
nonNull shouldNot beNull() // Passes