Class Assertions
java.lang.Object
org.soliscode.test.assertions.Assertions
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:
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.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.static <T> void
assertInstanceOf
(Class<T> expectedType, Object actual, Supplier<String> messageSupplier) Asserts that the object is not a instance of a class.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.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.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.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.static <T extends Comparable<T>>
voidassertLessThan
(T first, T second) static <T extends Comparable<T>>
voidassertLessThan
(T first, T second, String message) static <T extends Comparable<T>>
voidassertLessThan
(T first, T second, Supplier<String> messageSupplier) static <T> void
assertNotInstanceOf
(Class<T> expectedType, Object actual) Asserts that the object is not a instance of a class.static <T> void
assertNotInstanceOf
(Class<T> expectedType, Object actual, String message) Asserts that the object is not a instance of a class.static void
assertThrowsAny
(@NotNull Collection<Class<? extends Throwable>> expectedTypes, @NotNull org.junit.jupiter.api.function.Executable executable) Asserts that the executable will throw one of a list of possible exception types.static void
assertThrowsAny
(@NotNull Collection<Class<? extends Throwable>> expectedTypes, @NotNull org.junit.jupiter.api.function.Executable executable, String message) Asserts that the executable will throw one of a list of possible exception types.static void
assertThrowsAny
(@NotNull Collection<Class<? extends Throwable>> expectedTypes, @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.static void
assertThrowsDifferent
(@NotNull Class<? extends Throwable> prohibitedType, @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.static void
assertThrowsDifferent
(@NotNull Class<? extends Throwable> prohibitedType, @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.static void
assertThrowsDifferent
(@NotNull Class<? extends Throwable> prohibitedType, @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.static void
assertThrowsDifferent
(@NotNull Collection<Class<? extends Throwable>> prohibitedTypes, @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.static void
assertThrowsDifferent
(@NotNull Collection<Class<? extends Throwable>> prohibitedTypes, @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.static void
assertThrowsDifferent
(@NotNull Collection<Class<? extends Throwable>> prohibitedTypes, @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.
-
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
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
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
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
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
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
-
assertLessThan
-
assertLessThan
public static <T extends Comparable<T>> void assertLessThan(T first, T second, Supplier<String> messageSupplier)
-