Class Assert

java.lang.Object
org.variantsync.diffdetective.util.Assert

public class Assert extends Object
Assertions which cannot be disabled.

Assertions should document preconditions and postconditions which aren't enforced by the type system. All assertions in this class throw AssertionError to abort the program execution. At no point an AssertionError should be catched and the normal control flow resumed. The only valid reasons to catch such an exception is to add additional information to the exception or to ensure a fast and correct program shutdown.

The default Java assertions are disabled by default which makes them unsuitable for this research project because correctness is a higher goal then a little performance. This class provides assertions in a similar manner as JUnit and should be used for all assertions outside of unit tests (for unit tests use JUnit's assertions). Disabling or Enabling Java's assert should make no difference whatsoever.

  • Constructor Details

    • Assert

      public Assert()
  • Method Details

    • assertTrue

      public static void assertTrue(boolean cond)
      Abort program execution if cond is false.

      If the checked condition is not obvious in the source code assertTrue(boolean,java.lang.String) should be used to help identifying issues quickly.

      Parameters:
      cond - the condition which has to be true
      Throws:
      AssertionError - if cond is false
    • assertTrue

      public static void assertTrue(boolean cond, Supplier<String> errorMessage)
      Abort program execution if cond is false.

      Overload of assertTrue(boolean,java.lang.String) for computationally expensive messages. It's used to save the little execution time to construct a helpful error message in the common case of a correct assumption.

      Parameters:
      cond - the condition which has to be true
      errorMessage - a supplier of a single message identifying what condition is checked
      Throws:
      AssertionError - if cond is false
    • assertTrue

      public static void assertTrue(boolean cond, String errorMessage)
      Abort program execution if cond is false.

      If errorMessage is computationally expensive, consider using assertTrue(boolean,java.util.function.Supplier<java.lang.String>).

      Parameters:
      cond - the condition which has to be true
      errorMessage - a message identifying what condition is checked
      Throws:
      AssertionError - if cond is false
    • assertFalse

      public static void assertFalse(boolean condition)
      Abort program execution if condition is true.

      If the checked condition is not obvious in the source code assertTrue(boolean,java.lang.String) should be used to help identifying issues quickly.

      Parameters:
      condition - the condition which has to be false
      Throws:
      AssertionError - if condition is true
    • assertFalse

      public static void assertFalse(boolean condition, Supplier<String> errorMessage)
    • assertFalse

      public static void assertFalse(boolean condition, String errorMessage)
    • fail

      public static void fail(String errorMessage)
      Throws AssertionError with errorMessage as error message.
    • assertNotNull

      public static void assertNotNull(Object o)
      Abort program execution if o is null.
    • assertNull

      public static void assertNull(Object o)
      Abort program execution if o is not null.
    • assertEquals

      public static <T> void assertEquals(T expected, T actual)