Class Assertions
- java.lang.Object
-
- com.igormaznitsa.meta.common.utils.Assertions
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Assertions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 java.util.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(java.lang.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(java.lang.String failMessage, T object)
Assert that value is not nullstatic <T> T
assertNotNull(T object)
Assert that value is not nullstatic <T> T
assertNull(java.lang.String failMessage, T object)
Assert that value is nullstatic <T> T
assertNull(T object)
Assert that value is nullstatic void
assertTrue(java.lang.String message, boolean condition)
Assert condition flag is TRUE.static java.lang.Error
fail(java.lang.String message)
Throw assertion error for some cause
-
-
-
Method Detail
-
fail
public static java.lang.Error fail(java.lang.String message)
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:
java.lang.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:
java.lang.AssertionError
- it will be thrown if the value is not null- Since:
- 1.0
-
assertNull
public static <T> T assertNull(java.lang.String failMessage, T object)
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:
java.lang.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:
java.lang.AssertionError
- it will be thrown if the value is null- Since:
- 1.0
-
assertNotNull
public static <T> T assertNotNull(java.lang.String failMessage, T object)
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:
java.lang.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:
java.lang.AssertionError
- it will be thrown if either array is null or it contains null- Since:
- 1.0
-
assertTrue
public static void assertTrue(java.lang.String message, boolean condition)
Assert condition flag is TRUE. GEL will be notified about error.- Parameters:
message
- message describing situationcondition
- condition which must be true- Throws:
java.lang.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:
java.lang.AssertionError
- if the value id not equal to the etalon- Since:
- 1.1.1
-
assertFalse
public static void assertFalse(java.lang.String message, boolean condition)
Assert condition flag is FALSE. GEL will be notified about error.- Parameters:
message
- message describing situationcondition
- condition which must be false- Throws:
java.lang.AssertionError
- if the condition is true- Since:
- 1.0
-
assertDoesntContainNull
public static <T extends java.util.Collection<?>> T assertDoesntContainNull(T collection)
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:
java.lang.AssertionError
- it will be thrown if either collection is null or it contains null- Since:
- 1.0
-
assertNotDisposed
public static <T extends Disposable> T assertNotDisposed(T disposable)
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
public static <T> T assertAmong(T obj, @MayContainNull T... list)
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:
java.lang.AssertionError
- if object is not found among defined ones- Since:
- 1.0.2
-
assertIsValid
public static <T> T assertIsValid(T obj, Validator<T> validator)
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
-
-