Class CommonsAssert

java.lang.Object
com.helger.base.mock.CommonsAssert

@Immutable public class CommonsAssert extends Object
Extensions for the default JUnit assertions.
Author:
Philip Helger
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final float
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    assertEquals(boolean x, boolean y)
    Assert that two boolean values are equal.
    static void
    assertEquals(boolean x, @NonNull Boolean y)
    Assert that a boolean primitive and a Boolean object are equal.
    static void
    assertEquals(double @Nullable [] x, double @Nullable [] y)
    Assert that two double arrays are element-wise equal within the allowed rounding difference.
    static void
    assertEquals(double x, double y)
    Assert that two double values are equal within the allowed rounding difference.
    static void
    assertEquals(double x, @NonNull Double y)
    Assert that a double primitive and a Double object are equal within the allowed rounding difference.
    static void
    assertEquals(float @Nullable [] x, float @Nullable [] y)
    Assert that two float arrays are element-wise equal within the allowed rounding difference.
    static void
    assertEquals(float x, float y)
    Assert that two float values are equal within the allowed rounding difference.
    static void
    assertEquals(float x, @NonNull Float y)
    Assert that a float primitive and a Float object are equal within the allowed rounding difference.
    static <T> void
    assertEquals(@Nullable T x, @Nullable T y)
    Like JUnit assertEquals but using EqualsHelper.
    static void
    assertEquals(@Nullable String sUserMsg, boolean x, boolean y)
    Assert that two boolean values are equal, with a custom message.
    static void
    assertEquals(@Nullable String sUserMsg, double x, double y)
    Assert that two double values are equal within the allowed rounding difference, with a custom message.
    static void
    assertEquals(@Nullable String sUserMsg, float x, float y)
    Assert that two float values are equal within the allowed rounding difference, with a custom message.
    static <T> void
    assertEquals(@Nullable String sUserMsg, @Nullable T x, @Nullable T y)
    Like JUnit assertEquals but using EqualsHelper.
    static void
    assertNotEquals(boolean x, boolean y)
    Assert that two boolean values are not equal.
    static void
    assertNotEquals(boolean x, @NonNull Boolean y)
    Assert that a boolean primitive and a Boolean object are not equal.
    static <T> void
    assertNotEquals(@Nullable T x, @Nullable T y)
    Like JUnit assertNotEquals but using EqualsHelper.
    static void
    assertNotEquals(@Nullable String sUserMsg, boolean x, boolean y)
    Assert that two boolean values are not equal, with a custom message.
    static <T> void
    assertNotEquals(@Nullable String sUserMsg, @Nullable T x, @Nullable T y)
    Like JUnit assertNotEquals but using EqualsHelper.
    static void
    Unconditionally fail with a default message.
    static void
    fail(@NonNull String sMsg)
    Unconditionally fail with the provided message.

    Methods inherited from class java.lang.Object

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

    • FLOAT_ALLOWED_ROUNDING_DIFFERENCE

      public static final float FLOAT_ALLOWED_ROUNDING_DIFFERENCE
      See Also:
    • DOUBLE_ALLOWED_ROUNDING_DIFFERENCE

      public static final double DOUBLE_ALLOWED_ROUNDING_DIFFERENCE
      See Also:
  • Constructor Details

    • CommonsAssert

      protected CommonsAssert()
  • Method Details

    • fail

      public static void fail()
      Unconditionally fail with a default message.
    • fail

      public static void fail(@NonNull String sMsg)
      Unconditionally fail with the provided message.
      Parameters:
      sMsg - The failure message. May not be null.
    • assertEquals

      public static void assertEquals(boolean x, boolean y)
      Assert that two boolean values are equal.
      Parameters:
      x - First value.
      y - Second value.
    • assertEquals

      public static void assertEquals(boolean x, @NonNull Boolean y)
      Assert that a boolean primitive and a Boolean object are equal.
      Parameters:
      x - First value.
      y - Second value. May not be null.
    • assertNotEquals

      public static void assertNotEquals(boolean x, boolean y)
      Assert that two boolean values are not equal.
      Parameters:
      x - First value.
      y - Second value.
    • assertNotEquals

      public static void assertNotEquals(boolean x, @NonNull Boolean y)
      Assert that a boolean primitive and a Boolean object are not equal.
      Parameters:
      x - First value.
      y - Second value. May not be null.
    • assertNotEquals

      public static void assertNotEquals(@Nullable String sUserMsg, boolean x, boolean y)
      Assert that two boolean values are not equal, with a custom message.
      Parameters:
      sUserMsg - Optional user message. May be null.
      x - First value.
      y - Second value.
    • assertEquals

      public static void assertEquals(@Nullable String sUserMsg, boolean x, boolean y)
      Assert that two boolean values are equal, with a custom message.
      Parameters:
      sUserMsg - Optional user message. May be null.
      x - First value.
      y - Second value.
    • assertEquals

      public static void assertEquals(double x, double y)
      Assert that two double values are equal within the allowed rounding difference.
      Parameters:
      x - First value.
      y - Second value.
    • assertEquals

      public static void assertEquals(double x, @NonNull Double y)
      Assert that a double primitive and a Double object are equal within the allowed rounding difference.
      Parameters:
      x - First value.
      y - Second value. May not be null.
    • assertEquals

      public static void assertEquals(@Nullable String sUserMsg, double x, double y)
      Assert that two double values are equal within the allowed rounding difference, with a custom message.
      Parameters:
      sUserMsg - Optional user message. May be null.
      x - First value.
      y - Second value.
    • assertEquals

      public static void assertEquals(float x, float y)
      Assert that two float values are equal within the allowed rounding difference.
      Parameters:
      x - First value.
      y - Second value.
    • assertEquals

      public static void assertEquals(float x, @NonNull Float y)
      Assert that a float primitive and a Float object are equal within the allowed rounding difference.
      Parameters:
      x - First value.
      y - Second value. May not be null.
    • assertEquals

      public static void assertEquals(@Nullable String sUserMsg, float x, float y)
      Assert that two float values are equal within the allowed rounding difference, with a custom message.
      Parameters:
      sUserMsg - Optional user message. May be null.
      x - First value.
      y - Second value.
    • assertEquals

      public static <T> void assertEquals(@Nullable T x, @Nullable T y)
      Like JUnit assertEquals but using EqualsHelper.
      Type Parameters:
      T - data type to compare
      Parameters:
      x - Fist object. May be null
      y - Second object. May be null.
    • assertEquals

      public static <T> void assertEquals(@Nullable String sUserMsg, @Nullable T x, @Nullable T y)
      Like JUnit assertEquals but using EqualsHelper.
      Type Parameters:
      T - data type to compare
      Parameters:
      sUserMsg - Optional user message. May be null.
      x - Fist object. May be null
      y - Second object. May be null.
    • assertNotEquals

      public static <T> void assertNotEquals(@Nullable T x, @Nullable T y)
      Like JUnit assertNotEquals but using EqualsHelper.
      Type Parameters:
      T - data type to compare
      Parameters:
      x - Fist object. May be null
      y - Second object. May be null.
    • assertNotEquals

      public static <T> void assertNotEquals(@Nullable String sUserMsg, @Nullable T x, @Nullable T y)
      Like JUnit assertNotEquals but using EqualsHelper.
      Type Parameters:
      T - data type to compare
      Parameters:
      sUserMsg - Optional user message. May be null.
      x - Fist object. May be null
      y - Second object. May be null.
    • assertEquals

      public static void assertEquals(float @Nullable [] x, float @Nullable [] y)
      Assert that two float arrays are element-wise equal within the allowed rounding difference.
      Parameters:
      x - First array. May be null.
      y - Second array. May be null.
    • assertEquals

      public static void assertEquals(double @Nullable [] x, double @Nullable [] y)
      Assert that two double arrays are element-wise equal within the allowed rounding difference.
      Parameters:
      x - First array. May be null.
      y - Second array. May be null.