Class Assertions

java.lang.Object
org.soliscode.test.assertions.Assertions

public class Assertions extends Object
Utility class containing methods that support asserting conditions in tests. These methods are complimentary to the assertions provided in the Assertions class provided by the JUnit library
Author:
evanbergstrom
See Also:
  • Assertions
  • Method Details

    • assertThrowsAny

      public static void assertThrowsAny(@NotNull @NotNull Collection<Class<? extends Throwable>> expectedTypes, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable)
      Asserts that the executable will throw one of a list of possible exception types.
      Parameters:
      expectedTypes - the exception types that the executable should throw.
      executable - the executable to test.
    • assertThrowsAny

      public static void assertThrowsAny(@NotNull @NotNull Collection<Class<? extends Throwable>> expectedTypes, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable, String message)
      Asserts that the executable will throw one of a list of possible exception types.
      Parameters:
      expectedTypes - the exception types that the executable should throw.
      executable - the executable to test.
      message - the message to include in the exception if the assertions fails.
    • assertThrowsAny

      public static void assertThrowsAny(@NotNull @NotNull Collection<Class<? extends Throwable>> expectedTypes, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable, Supplier<String> messageSupplier)
      Asserts that the executable will throw one of a list of possible exception types.
      Parameters:
      expectedTypes - the exception types that the executable should throw.
      executable - the executable to test.
      messageSupplier - the supplier of the message to include in the exception if the assertions fails.
    • assertThrowsDifferent

      public static void assertThrowsDifferent(@NotNull @NotNull Class<? extends Throwable> prohibitedType, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable)
      Asserts that the executable will throw an exception that is not one of a list of prohibited exception types.
      Parameters:
      prohibitedType - the exception type that the executable should not throw.
      executable - the executable to test.
    • assertThrowsDifferent

      public static void assertThrowsDifferent(@NotNull @NotNull Collection<Class<? extends Throwable>> prohibitedTypes, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable)
      Asserts that the executable will throw an exception that is not one of a list of prohibited exception types.
      Parameters:
      prohibitedTypes - the exception types that the executable should not throw.
      executable - the executable to test.
    • assertThrowsDifferent

      public static void assertThrowsDifferent(@NotNull @NotNull Class<? extends Throwable> prohibitedType, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable, String message)
      Asserts that the executable will throw an exception that is not one of a list of prohibited exception types.
      Parameters:
      prohibitedType - the exception type that the executable should not throw.
      executable - the executable to test.
      message - the message to include in the exception if the assertions fails.
    • assertThrowsDifferent

      public static void assertThrowsDifferent(@NotNull @NotNull Collection<Class<? extends Throwable>> prohibitedTypes, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable, String message)
      Asserts that the executable will throw an exception that is not one of a list of prohibited exception types.
      Parameters:
      prohibitedTypes - the exception types that the executable should not throw.
      executable - the executable to test.
      message - the message to include in the exception if the assertions fails.
    • assertThrowsDifferent

      public static void assertThrowsDifferent(@NotNull @NotNull Collection<Class<? extends Throwable>> prohibitedTypes, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable, Supplier<String> messageSupplier)
      Asserts that the executable will throw an exception that is not one of a list of prohibited exception types.
      Parameters:
      prohibitedTypes - the exception types that the executable should not throw.
      executable - the executable to test.
      messageSupplier - the supplier of the message to include in the exception if the assertions fails.
    • assertThrowsDifferent

      public static void assertThrowsDifferent(@NotNull @NotNull Class<? extends Throwable> prohibitedType, @NotNull @NotNull org.junit.jupiter.api.function.Executable executable, Supplier<String> messageSupplier)
      Asserts that the executable will throw an exception that is not one of a list of prohibited exception types.
      Parameters:
      prohibitedType - the exception type that the executable should not throw.
      executable - the executable to test.
      messageSupplier - the supplier of the message to include in the exception if the assertions fails.
    • assertNotInstanceOf

      public static <T> void assertNotInstanceOf(Class<T> expectedType, Object actual)
      Asserts that the object is not a instance of a class.
      Type Parameters:
      T - The type that is not expected.
      Parameters:
      expectedType - The type that the object being tested is expected not to be.
      actual - The object being tested.
    • assertNotInstanceOf

      public static <T> void assertNotInstanceOf(Class<T> expectedType, Object actual, String message)
      Asserts that the object is not a instance of a class.
      Type Parameters:
      T - The type that is not expected.
      Parameters:
      expectedType - The type that the object being tested is expected not to be.
      actual - The object being tested.
      message - the message to include in the exception if the assertions fails.
    • assertInstanceOf

      public static <T> void assertInstanceOf(Class<T> expectedType, Object actual, Supplier<String> messageSupplier)
      Asserts that the object is not a instance of a class.
      Type Parameters:
      T - The type that is not expected.
      Parameters:
      expectedType - The type that the object being tested is expected not to be.
      actual - The object being tested.
      messageSupplier - the supplier of the message to include in the exception if the assertions fails.
    • assertImplementsOnly

      public static void assertImplementsOnly(Class<?> expected, Object actual)
      Asserts that an object is an instance of a class that implements interfaces only from a set of permitted interfaces. This will only test for interfaces that the class of the object implements directly.
      Parameters:
      expected - the classes or interfaces that the object can be an instance of.
      actual - The object being tested.
    • assertImplementsOnly

      public static void assertImplementsOnly(Collection<Class<?>> expected, Object actual)
      Asserts that an object is an instance of a class that implements interfaces only from a set of permitted interfaces. This will only test for interfaces that the class of the object implements directly.
      Parameters:
      expected - the classes or interfaces that the object can be an instance of.
      actual - The object being tested.
    • assertInstanceOfOnly

      public static void assertInstanceOfOnly(Class<?> expected, Object actual, String message)
      Asserts that an object is an instance of a class that implements interfaces only from a set of permitted interfaces. This will only test for interfaces that the class of the object implements directly.
      Parameters:
      expected - the classes or interfaces that the object can be an instance of.
      actual - The object being tested.
      message - the message to include in the exception if the assertions fails.
    • assertInstanceOfOnly

      public static void assertInstanceOfOnly(Collection<Class<?>> expected, Object actual, String message)
      Asserts that an object is an instance of a class that implements interfaces only from a set of permitted interfaces. This will only test for interfaces that the class of the object implements directly.
      Parameters:
      expected - the classes or interfaces that the object can be an instance of.
      actual - The object being tested.
      message - the message to include in the exception if the assertions fails.
    • assertInstanceOfOnly

      public static void assertInstanceOfOnly(Class<?> expected, Object actual, Supplier<String> messageSupplier)
      Asserts that an object is an instance of a class that implements interfaces only from a set of permitted interfaces. This will only test for interfaces that the class of the object implements directly.
      Parameters:
      expected - the classes or interfaces that the object can be an instance of.
      actual - The object being tested.
      messageSupplier - the supplier of the message to include in the exception if the assertions fails.
    • assertInstanceOfOnly

      public static void assertInstanceOfOnly(Collection<Class<?>> expected, Object actual, Supplier<String> messageSupplier)
      Asserts that an object is an instance of a class that implements interfaces only from a set of permitted interfaces. This will only test for interfaces that the class of the object implements directly.
      Parameters:
      expected - the classes or interfaces that the object can be an instance of.
      actual - The object being tested.
      messageSupplier - the supplier of the message to include in the exception if the assertions fails.
    • assertLessThan

      public static <T extends Comparable<T>> void assertLessThan(T first, T second)
    • assertLessThan

      public static <T extends Comparable<T>> void assertLessThan(T first, T second, String message)
    • assertLessThan

      public static <T extends Comparable<T>> void assertLessThan(T first, T second, Supplier<String> messageSupplier)