Class Assertions

java.lang.Object
com.mongodb.kafka.connect.util.Assertions

public final class Assertions extends Object
All methods throw AssertionError and should be used to check conditions which may be violated if and only if the driver code is incorrect. The intended usage of these methods is the same as of the Java assert statement. The reason for not using the assert statements is that they are not always enabled. We prefer having internal checks always done at the cost of our code doing a relatively small amount of additional work in production. The assert... methods return values to open possibilities of being used fluently.
  • Method Details

    • assertNull

      @Nullable public static <T> T assertNull(@Nullable T value) throws AssertionError
      Type Parameters:
      T - The type of value.
      Parameters:
      value - A value to check.
      Returns:
      null.
      Throws:
      AssertionError - If value is not null.
    • assertNotNull

      public static <T> T assertNotNull(@Nullable T value) throws AssertionError
      Type Parameters:
      T - The type of value.
      Parameters:
      value - A value to check.
      Returns:
      value
      Throws:
      AssertionError - If value is null.
    • assertTrue

      public static boolean assertTrue(boolean value) throws AssertionError
      Parameters:
      value - A value to check.
      Returns:
      true.
      Throws:
      AssertionError - If value is false.
    • assertFalse

      public static boolean assertFalse(boolean value) throws AssertionError
      Parameters:
      value - A value to check.
      Returns:
      false.
      Throws:
      AssertionError - If value is true.
    • fail

      public static AssertionError fail() throws AssertionError
      Returns:
      Never completes normally. The return type is AssertionError to allow writing throw fail(). This may be helpful in non-void methods.
      Throws:
      AssertionError - Always
    • fail

      public static AssertionError fail(String msg) throws AssertionError
      Parameters:
      msg - The failure message.
      Returns:
      Never completes normally. The return type is AssertionError to allow writing throw fail("failure message"). This may be helpful in non-void methods.
      Throws:
      AssertionError - Always