Class Assert

java.lang.Object
com.pnfsoftware.jeb.util.base.Assert

public abstract class Assert extends Object
A replacement for built-in asserts. Production-compatible assert-likes. Do not throw AssertionError on failure; instead, a RuntimeException is raised.

Assert methods throw RuntimeException. The stacktrace of such an exception is adjusted to reflect the actual code line where a(...) or fail(...) was called.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    a(boolean expression)
    Assert that a condition is true.
    static void
    a(boolean expression, String message)
    Assert that a condition is true.
    static void
    a(boolean expression, String message, Object... args)
    Assert that a condition is true.
    static void
    Fail ONLY on debug builds.
    static void
    debugFail(String message)
    Fail ONLY on debug builds.
    static void
    Fail only on debug builds by throwing the provided throwable, or logging it on release builds.
    static void
    Unconditionally fail.
    static void
    fail(String message)
    Unconditionally fail.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Assert

      public Assert()
  • Method Details

    • a

      public static void a(boolean expression, String message)
      Assert that a condition is true.
      Parameters:
      expression - condition to verify
      message - optional failure message
    • a

      public static void a(boolean expression, String message, Object... args)
      Assert that a condition is true.
      Parameters:
      expression - condition to verify
      message - optional failure message format
      args - optional message format arguments
    • a

      public static void a(boolean expression)
      Assert that a condition is true.
      Parameters:
      expression - condition to verify
    • fail

      public static void fail(String message)
      Unconditionally fail.
      Parameters:
      message - optional failure message
    • fail

      public static void fail()
      Unconditionally fail.
    • debugFail

      public static void debugFail(String message)
      Fail ONLY on debug builds. Use carefully; this method can yield side-effect bugs on release builds that would have otherwise be caught in debug mode.
      Parameters:
      message - optional failure message
    • debugFail

      public static void debugFail()
      Fail ONLY on debug builds. Use carefully; this method can yield side-effect bugs on release builds that would have otherwise be caught in debug mode.
    • debugFail

      public static void debugFail(Throwable t)
      Fail only on debug builds by throwing the provided throwable, or logging it on release builds.
      Parameters:
      t - throwable to report