abstract class Assert
Assertion utility class that assists in validating arguments.
Useful for identifying programmer errors early and clearly at runtime.
For example, if the contract of a public method states it does not allow null arguments, Assert can be used to validate that contract. Doing this clearly indicates a contract violation when it occurs and protects the class's invariants.
Typically used to validate method arguments rather than configuration properties, to check for cases that are usually programmer errors rather than configuration errors. In contrast to configuration initialization code, there is usually no point in falling back to defaults in such methods.
This class is similar to JUnit's assertion library. If an argument value is deemed invalid, an IllegalArgumentException is thrown (typically). For example:
Assert.notNull(clazz, "The class must not be null"); Assert.isTrue(i > 0, "The value must be greater than zero");
Mainly for internal use within the framework; consider Apache's Commons Lang for a more comprehensive suite of String utilities.
Author
Keith Donald
Author
Juergen Hoeller
Author
Sam Brannen
Author
Colin Sampaleanu
Author
Rob Harrop
Since
1.1.2
Assert()
Assertion utility class that assists in validating arguments. Useful for identifying programmer errors early and clearly at runtime. For example, if the contract of a public method states it does not allow Typically used to validate method arguments rather than configuration properties, to check for cases that are usually programmer errors rather than configuration errors. In contrast to configuration initialization code, there is usually no point in falling back to defaults in such methods. This class is similar to JUnit's assertion library. If an argument value is deemed invalid, an IllegalArgumentException is thrown (typically). For example:
Mainly for internal use within the framework; consider Apache's Commons Lang for a more comprehensive suite of |
open static fun doesNotContain(textToSearch: String, substring: String, message: String): Unit
Assert that the given text does not contain the given substring.
open static fun doesNotContain(textToSearch: String, substring: String, messageSupplier: Supplier<String>): Unit
Assert that the given text does not contain the given substring.
open static fun doesNotContain(textToSearch: String, substring: String): Unit |
|
open static fun hasLength(text: String, message: String): Unit
Assert that the given String is not empty; that is, it must not be
open static fun hasLength(text: String, messageSupplier: Supplier<String>): Unit
Assert that the given String is not empty; that is, it must not be
open static fun hasLength(text: String): Unit |
|
open static fun hasText(text: String, message: String): Unit
Assert that the given String contains valid text content; that is, it must not be
open static fun hasText(text: String, messageSupplier: Supplier<String>): Unit
Assert that the given String contains valid text content; that is, it must not be
open static fun hasText(text: String): Unit |
|
open static fun isAssignable(superType: Class<*>, subType: Class<*>, message: String): Unit
Assert that
open static fun isAssignable(superType: Class<*>, subType: Class<*>, messageSupplier: Supplier<String>): Unit
Assert that
open static fun isAssignable(superType: Class<*>, subType: Class<*>): Unit
Assert that
|
|
open static fun isInstanceOf(type: Class<*>, obj: Any, message: String): Unit
Assert that the provided object is an instance of the provided class.
open static fun isInstanceOf(type: Class<*>, obj: Any, messageSupplier: Supplier<String>): Unit
Assert that the provided object is an instance of the provided class.
open static fun isInstanceOf(type: Class<*>, obj: Any): Unit
Assert that the provided object is an instance of the provided class.
|
|
open static fun isNull(object: Any, message: String): Unit
Assert that an object is
open static fun isNull(object: Any, messageSupplier: Supplier<String>): Unit
Assert that an object is
open static fun isNull(object: Any): Unit |
|
open static fun isTrue(expression: Boolean, message: String): Unit
Assert a boolean expression, throwing an
open static fun isTrue(expression: Boolean, messageSupplier: Supplier<String>): Unit
Assert a boolean expression, throwing an
open static fun isTrue(expression: Boolean): Unit |
|
open static fun noNullElements(array: Array<Any>, message: String): Unit
Assert that an array contains no Note: Does not complain if the array is empty!
open static fun noNullElements(array: Array<Any>, messageSupplier: Supplier<String>): Unit
Assert that an array contains no Note: Does not complain if the array is empty!
open static fun noNullElements(array: Array<Any>): Unit |
|
open static fun notEmpty(array: Array<Any>, message: String): Unit
Assert that an array contains elements; that is, it must not be
open static fun notEmpty(array: Array<Any>, messageSupplier: Supplier<String>): Unit
Assert that an array contains elements; that is, it must not be
open static fun notEmpty(array: Array<Any>): Unitopen static fun notEmpty(collection: MutableCollection<*>): Unitopen static fun notEmpty(map: MutableMap<*, *>): Unitopen static fun notEmpty(collection: MutableCollection<*>, message: String): Unit
Assert that a collection contains elements; that is, it must not be
open static fun notEmpty(collection: MutableCollection<*>, messageSupplier: Supplier<String>): Unit
Assert that a collection contains elements; that is, it must not be
open static fun notEmpty(map: MutableMap<*, *>, message: String): Unit
Assert that a Map contains entries; that is, it must not be
open static fun notEmpty(map: MutableMap<*, *>, messageSupplier: Supplier<String>): Unit
Assert that a Map contains entries; that is, it must not be
|
|
open static fun notNull(object: Any, message: String): Unit
Assert that an object is not
open static fun notNull(object: Any, messageSupplier: Supplier<String>): Unit
Assert that an object is not
open static fun notNull(object: Any): Unit |
|
open static fun state(expression: Boolean, message: String): Unit
Assert a boolean expression, throwing an Call
open static fun state(expression: Boolean, messageSupplier: Supplier<String>): Unit
Assert a boolean expression, throwing an Call
open static fun state(expression: Boolean): Unit |