Class Assertions

java.lang.Object
com.igormaznitsa.meta.common.utils.Assertions

@Weight(LIGHT) public final class Assertions extends Object
Set of auxiliary methods for assertion.
Since:
1.0
  • Constructor Details

    • Assertions

      private Assertions()
  • Method Details

    • fail

      public static Error fail(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:
      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

      public static <T> T assertNull(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 null
      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.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

      public static <T> T assertNotNull(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 null
      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.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

      public static void assertTrue(String message, boolean condition)
      Assert condition flag is TRUE. GEL will be notified about error.
      Parameters:
      message - message describing situation
      condition - 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 value
      value - 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

      public static void assertFalse(String message, boolean condition)
      Assert condition flag is FALSE. GEL will be notified about error.
      Parameters:
      message - message describing situation
      condition - condition which must be false
      Throws:
      AssertionError - if the condition is true
      Since:
      1.0
    • assertDoesntContainNull

      public static <T extends 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:
      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 checked
      list - 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

      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 checked
      validator - 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