Class Assertions
java.lang.Object
com.igormaznitsa.meta.common.utils.Assertions
Set of auxiliary methods for assertion.
- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
assertAmong
(T obj, T... list) Check that object is presented among provided elements and replace the object by equal element from the list.static <T extends Collection<?>>
TassertDoesntContainNull
(T collection) Assert that collection doesn't contain null value.static <T> T[]
assertDoesntContainNull
(T[] array) Assert that array doesn't contain null value.static <T> T
assertEquals
(T etalon, T value) Assert that value is equal to some etalon value.static void
assertFalse
(String message, boolean condition) Assert condition flag is FALSE.static <T> T
assertIsValid
(T obj, Validator<T> validator) Check an object by a validator.static <T extends Disposable>
TassertNotDisposed
(T disposable) Assert that a disposable object is not disposed.static <T> T
assertNotNull
(String failMessage, T object) Assert that value is not nullstatic <T> T
assertNotNull
(T object) Assert that value is not nullstatic <T> T
assertNull
(String failMessage, T object) Assert that value is nullstatic <T> T
assertNull
(T object) Assert that value is nullstatic void
assertTrue
(String message, boolean condition) Assert condition flag is TRUE.static Error
Throw assertion error for some cause
-
Constructor Details
-
Assertions
private Assertions()
-
-
Method Details
-
fail
Throw assertion error for some cause- Parameters:
message
- description of the cause.- Returns:
- generated error, but it throws AssertionError before return so that the value just for IDE.
- Throws:
AssertionError
- will be thrown- Since:
- 1.0
-
assertNull
public static <T> T assertNull(T object) Assert that value is null- Type Parameters:
T
- type of the object to check- Parameters:
object
- the object to check- Returns:
- the same input parameter if all is ok
- Throws:
AssertionError
- it will be thrown if the value is not null- Since:
- 1.0
-
assertNull
Assert that value is null- Type Parameters:
T
- type of the object to check- Parameters:
failMessage
- the message to be provided for failure, can be nullobject
- the object to check- Returns:
- the same input parameter if all is ok
- Throws:
AssertionError
- it will be thrown if the value is not null- Since:
- 1.1.0
-
assertNotNull
public static <T> T assertNotNull(T object) Assert that value is not null- Type Parameters:
T
- type of the object to check- Parameters:
object
- the object to check- Returns:
- the same input parameter if all is ok
- Throws:
AssertionError
- it will be thrown if the value is null- Since:
- 1.0
-
assertNotNull
Assert that value is not null- Type Parameters:
T
- type of the object to check- Parameters:
failMessage
- the message to be provided as error description, can be nullobject
- the object to check- Returns:
- the same input parameter if all is ok
- Throws:
AssertionError
- it will be thrown if the value is null- Since:
- 1.1.0
-
assertDoesntContainNull
public static <T> T[] assertDoesntContainNull(T[] array) Assert that array doesn't contain null value.- Type Parameters:
T
- type of the object to check- Parameters:
array
- an array to be checked for null value- Returns:
- the same input parameter if all is ok
- Throws:
AssertionError
- it will be thrown if either array is null or it contains null- Since:
- 1.0
-
assertTrue
Assert condition flag is TRUE. GEL will be notified about error.- Parameters:
message
- message describing situationcondition
- condition which must be true- Throws:
AssertionError
- if the condition is not true- Since:
- 1.0
-
assertEquals
public static <T> T assertEquals(T etalon, T value) Assert that value is equal to some etalon value.- Type Parameters:
T
- type of object to be checked.- Parameters:
etalon
- etalon valuevalue
- value to check- Returns:
- value if it is equal to etalon
- Throws:
AssertionError
- if the value id not equal to the etalon- Since:
- 1.1.1
-
assertFalse
Assert condition flag is FALSE. GEL will be notified about error.- Parameters:
message
- message describing situationcondition
- condition which must be false- Throws:
AssertionError
- if the condition is true- Since:
- 1.0
-
assertDoesntContainNull
Assert that collection doesn't contain null value.- Type Parameters:
T
- type of collection to check- Parameters:
collection
- a collection to be checked for null value- Returns:
- the same input parameter if all is ok
- Throws:
AssertionError
- it will be thrown if either collection is null or it contains null- Since:
- 1.0
-
assertNotDisposed
Assert that a disposable object is not disposed.- Type Parameters:
T
- type of the object- Parameters:
disposable
- disposable object to be checked- Returns:
- the disposable object if it is not disposed yet
- Throws:
AlreadyDisposedError
- it will be thrown if the object is already disposed;- Since:
- 1.0
-
assertAmong
Check that object is presented among provided elements and replace the object by equal element from the list.- Type Parameters:
T
- type of object- Parameters:
obj
- object to be checkedlist
- list of elements for checking- Returns:
- equal element provided in the list
- Throws:
AssertionError
- if object is not found among defined ones- Since:
- 1.0.2
-
assertIsValid
Check an object by a validator.- Type Parameters:
T
- object type- Parameters:
obj
- object to be checkedvalidator
- validator for the operation- Returns:
- the object if it is valid
- Throws:
InvalidObjectError
- will be thrown if the object is invalid- Since:
- 1.0.2
-