Class Assert

java.lang.Object
com.antithesis.sdk.Assert

public final class Assert extends Object
The Assert class enables defining test properties about your program or workload.

Each static method in this class takes a parameter called message, which is a string literal identifier used to aggregate assertions. Antithesis generates one test property per unique message. This test property will be named message in the triage report.

Each static method also takes a parameter called details, which is an ObjectNode reference of optional additional information provided by the user to add context for assertion failures. The information that is logged will appear in the logs section of a triage report. Normally the values in details are evaluated at runtime.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Types of assertions available
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    always(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details)
    Assert that condition is true every time this function is called, and that it is called at least once.
    static void
    alwaysOrUnreachable(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details)
    Assert that condition is true every time this function is called.
    static void
    rawAssert(Assert.AssertType assertType, String displayType, String className, String functionName, String fileName, int beginLine, int beginColumn, String id, boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details, boolean hit, boolean mustHit)
    This is a low-level method designed to be used by third-party frameworks.
    static void
    reachable(String message, com.fasterxml.jackson.databind.node.ObjectNode details)
    Assert that a line of code is reached at least once.
    static void
    sometimes(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details)
    Assert that condition is true at least one time that this function was called.
    static void
    unreachable(String message, com.fasterxml.jackson.databind.node.ObjectNode details)
    Assert that a line of code is never reached.

    Methods inherited from class java.lang.Object

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

    • Assert

      public Assert()
      Default constructor
  • Method Details

    • always

      public static void always(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details)
      Assert that condition is true every time this function is called, and that it is called at least once. The corresponding test property will be viewable in the Antithesis SDK: Always group of your triage report.
      Parameters:
      condition - the condition being asserted. Evaluated at runtime.
      message - a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.
      details - additional details that provide greater context for assertion success/failure. Evaluated at runtime.
    • alwaysOrUnreachable

      public static void alwaysOrUnreachable(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details)
      Assert that condition is true every time this function is called. The corresponding test property will pass even if the assertion is never encountered.

      The corresponding test property will be viewable in the Antithesis SDK: Always group of your triage report.

      Parameters:
      condition - the condition being asserted. Evaluated at runtime.
      message - a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.
      details - additional details that provide greater context for assertion success/failure. Evaluated at runtime.
    • sometimes

      public static void sometimes(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details)
      Assert that condition is true at least one time that this function was called. (If the assertion is never encountered, the test property will therefore fail.) This test property will be viewable in the Antithesis SDK: Sometimes group.
      Parameters:
      condition - the condition being asserted. Evaluated at runtime.
      message - a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.
      details - additional details that provide greater context for assertion success/failure. Evaluated at runtime.
    • unreachable

      public static void unreachable(String message, com.fasterxml.jackson.databind.node.ObjectNode details)
      Assert that a line of code is never reached. The corresponding test property will fail if this method is ever called. (If it is never called the test property will therefore pass.) This test property will be viewable in the Antithesis SDK: Reachability assertions group.
      Parameters:
      message - a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.
      details - additional details that provide greater context for assertion success/failure. Evaluated at runtime.
    • reachable

      public static void reachable(String message, com.fasterxml.jackson.databind.node.ObjectNode details)
      Assert that a line of code is reached at least once. The corresponding test property will pass if this method is ever called. (If it is never called the test property will therefore fail.) This test property will be viewable in the Antithesis SDK: Reachability assertions group.
      Parameters:
      message - a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.
      details - additional details that provide greater context for assertion success/failure. Evaluated at runtime.
    • rawAssert

      public static void rawAssert(Assert.AssertType assertType, String displayType, String className, String functionName, String fileName, int beginLine, int beginColumn, String id, boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details, boolean hit, boolean mustHit)
      This is a low-level method designed to be used by third-party frameworks. Regular users of the assertions class should not call it.

      This is primarily intended for use by adapters from other diagnostic tools that intend to output Antithesis-style assertions.

      Be certain to provide an assertion catalog entry for each assertion issued with rawAssert(). Assertion catalog entries are also created using rawAssert(), by setting the value of the hit parameter to false.

      Please refer to the general Antithesis documentation regarding the use of the Fallback SDK for additional information.

      Parameters:
      assertType - must be a valid Assertion.AssertType value
      displayType - one of "Always", "AlwaysOrUnreachable", "Sometimes", "Reachable", "Unreachable"
      className - the name of the package and class containing this assertion
      functionName - the name of the method containing this assertion
      fileName - the name of the source file containing this assertion
      beginLine - the source line number where the assertion is located
      beginColumn - the source column number where the assertion is located
      id - the unique text associated with the assertion
      condition - the condition being asserted. Evaluated at runtime.
      message - a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable.
      details - additional details that provide greater context for assertion success/failure. Evaluated at runtime.
      hit - true if the assertion has been evaluated, false if the assertion is being added to the assertion catalog
      mustHit - true if the assertion is expected to be evaluated at least once, otherwise false