@UnstableApi
class Assertions


Provides methods for asserting the truth of expressions and properties.

Summary

Public functions

java-static Unit
@Pure
checkArgument(expression: Boolean)

Throws IllegalArgumentException if expression evaluates to false.

java-static Unit
@Pure
checkArgument(expression: Boolean, errorMessage: Any!)

Throws IllegalArgumentException if expression evaluates to false.

java-static Int
@Pure
checkIndex(index: Int, start: Int, limit: Int)

Throws IndexOutOfBoundsException if index falls outside the specified bounds.

java-static Unit

Throws IllegalStateException if the calling thread is not the application's main thread.

java-static String!
@EnsuresNonNull(value = [""#1""])
@Pure
checkNotEmpty(string: String?)

Throws IllegalArgumentException if string is null or zero length.

java-static String!
@EnsuresNonNull(value = [""#1""])
@Pure
checkNotEmpty(string: String?, errorMessage: Any!)

Throws IllegalArgumentException if string is null or zero length.

java-static T!
@EnsuresNonNull(value = [""#1""])
@Pure
<T> checkNotNull(reference: T?)

Throws NullPointerException if reference is null.

java-static T!
@EnsuresNonNull(value = [""#1""])
@Pure
<T> checkNotNull(reference: T?, errorMessage: Any!)

Throws NullPointerException if reference is null.

java-static Unit
@Pure
checkState(expression: Boolean)

Throws IllegalStateException if expression evaluates to false.

java-static Unit
@Pure
checkState(expression: Boolean, errorMessage: Any!)

Throws IllegalStateException if expression evaluates to false.

java-static T!
@EnsuresNonNull(value = [""#1""])
@Pure
<T> checkStateNotNull(reference: T?)

Throws IllegalStateException if reference is null.

java-static T!
@EnsuresNonNull(value = [""#1""])
@Pure
<T> checkStateNotNull(reference: T?, errorMessage: Any!)

Throws IllegalStateException if reference is null.

Public functions

checkArgument

@Pure
java-static fun checkArgument(expression: Boolean): Unit

Throws IllegalArgumentException if expression evaluates to false.

Parameters
expression: Boolean

The expression to evaluate.

Throws
java.lang.IllegalArgumentException

If expression is false.

checkArgument

@Pure
java-static fun checkArgument(expression: Boolean, errorMessage: Any!): Unit

Throws IllegalArgumentException if expression evaluates to false.

Parameters
expression: Boolean

The expression to evaluate.

errorMessage: Any!

The exception message if an exception is thrown. The message is converted to a String using valueOf.

Throws
java.lang.IllegalArgumentException

If expression is false.

checkIndex

@Pure
java-static fun checkIndex(index: Int, start: Int, limit: Int): Int

Throws IndexOutOfBoundsException if index falls outside the specified bounds.

Parameters
index: Int

The index to test.

start: Int

The start of the allowed range (inclusive).

limit: Int

The end of the allowed range (exclusive).

Returns
Int

The index that was validated.

Throws
java.lang.IndexOutOfBoundsException

If index falls outside the specified bounds.

checkMainThread

@Pure
java-static fun checkMainThread(): Unit

Throws IllegalStateException if the calling thread is not the application's main thread.

Throws
java.lang.IllegalStateException

If the calling thread is not the application's main thread.

checkNotEmpty

@EnsuresNonNull(value = [""#1""])
@Pure
java-static fun checkNotEmpty(string: String?): String!

Throws IllegalArgumentException if string is null or zero length.

Parameters
string: String?

The string to check.

Returns
String!

The non-null, non-empty string that was validated.

Throws
java.lang.IllegalArgumentException

If string is null or 0-length.

checkNotEmpty

@EnsuresNonNull(value = [""#1""])
@Pure
java-static fun checkNotEmpty(string: String?, errorMessage: Any!): String!

Throws IllegalArgumentException if string is null or zero length.

Parameters
string: String?

The string to check.

errorMessage: Any!

The exception message to use if the check fails. The message is converted to a string using valueOf.

Returns
String!

The non-null, non-empty string that was validated.

Throws
java.lang.IllegalArgumentException

If string is null or 0-length.

checkNotNull

@EnsuresNonNull(value = [""#1""])
@Pure
java-static fun <T> checkNotNull(reference: T?): T!

Throws NullPointerException if reference is null.

Parameters
<T>

The type of the reference.

reference: T?

The reference.

Returns
T!

The non-null reference that was validated.

Throws
java.lang.NullPointerException

If reference is null.

checkNotNull

@EnsuresNonNull(value = [""#1""])
@Pure
java-static fun <T> checkNotNull(reference: T?, errorMessage: Any!): T!

Throws NullPointerException if reference is null.

Parameters
<T>

The type of the reference.

reference: T?

The reference.

errorMessage: Any!

The exception message to use if the check fails. The message is converted to a string using valueOf.

Returns
T!

The non-null reference that was validated.

Throws
java.lang.NullPointerException

If reference is null.

checkState

@Pure
java-static fun checkState(expression: Boolean): Unit

Throws IllegalStateException if expression evaluates to false.

Parameters
expression: Boolean

The expression to evaluate.

Throws
java.lang.IllegalStateException

If expression is false.

checkState

@Pure
java-static fun checkState(expression: Boolean, errorMessage: Any!): Unit

Throws IllegalStateException if expression evaluates to false.

Parameters
expression: Boolean

The expression to evaluate.

errorMessage: Any!

The exception message if an exception is thrown. The message is converted to a String using valueOf.

Throws
java.lang.IllegalStateException

If expression is false.

checkStateNotNull

@EnsuresNonNull(value = [""#1""])
@Pure
java-static fun <T> checkStateNotNull(reference: T?): T!

Throws IllegalStateException if reference is null.

Parameters
<T>

The type of the reference.

reference: T?

The reference.

Returns
T!

The non-null reference that was validated.

Throws
java.lang.IllegalStateException

If reference is null.

checkStateNotNull

@EnsuresNonNull(value = [""#1""])
@Pure
java-static fun <T> checkStateNotNull(reference: T?, errorMessage: Any!): T!

Throws IllegalStateException if reference is null.

Parameters
<T>

The type of the reference.

reference: T?

The reference.

errorMessage: Any!

The exception message to use if the check fails. The message is converted to a string using valueOf.

Returns
T!

The non-null reference that was validated.

Throws
java.lang.IllegalStateException

If reference is null.