Class Invariants

java.lang.Object
com.renomad.minum.utils.Invariants

public final class Invariants extends Object
Utilities for asserting invariants within the code.
The purpose here is to make firm statements about the code. This is to help document the code, (e.g. at this point, x is the sum of the ...), to include testing mindset in the code, and to guard against adding bugs during maintenance.
  • Method Details

    • mustBeTrue

      public static void mustBeTrue(boolean predicate, String message)
      Specify something which must be true.

      Throws an InvariantException if false

      Parameters:
      predicate - the boolean expression that must be true at this point
      message - a message that will be included in the exception if this is false
    • mustBeFalse

      public static void mustBeFalse(boolean predicate, String message)
      Specify something which must be false

      Throws an InvariantException if true

      Parameters:
      predicate - the boolean expression that must be false at this point
      message - a message that will be included in the exception if this is true
    • mustNotBeNull

      public static <T> T mustNotBeNull(T object)
      specifies that the parameter must be not null.

      Throws an InvariantException if null.

      Returns:
      the object if not null