Class OptionalAssertions
- java.lang.Object
-
- com.github.robtimus.junit.support.OptionalAssertions
-
public final class OptionalAssertions extends Object
A collection of utility methods that support asserting conditions in tests forOptional
,OptionalInt
,OptionalLong
andOptionalDouble
.- Author:
- Rob Spoor
- Since:
- 2.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertIsEmpty(Optional<?> optional)
Asserts that the supplied optional is empty.static void
assertIsEmpty(Optional<?> optional, String message)
Asserts that the supplied optional is empty.static void
assertIsEmpty(Optional<?> optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalDouble optional)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalDouble optional, String message)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalDouble optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalInt optional)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalInt optional, String message)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalInt optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalLong optional)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalLong optional, String message)
Asserts that the supplied optional is empty.static void
assertIsEmpty(OptionalLong optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.static <T> T
assertIsPresent(Optional<T> optional)
Asserts that the supplied optional is not empty.static <T> T
assertIsPresent(Optional<T> optional, String message)
Asserts that the supplied optional is not empty.static <T> T
assertIsPresent(Optional<T> optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.static double
assertIsPresent(OptionalDouble optional)
Asserts that the supplied optional is not empty.static double
assertIsPresent(OptionalDouble optional, String message)
Asserts that the supplied optional is not empty.static double
assertIsPresent(OptionalDouble optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.static int
assertIsPresent(OptionalInt optional)
Asserts that the supplied optional is not empty.static int
assertIsPresent(OptionalInt optional, String message)
Asserts that the supplied optional is not empty.static int
assertIsPresent(OptionalInt optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.static long
assertIsPresent(OptionalLong optional)
Asserts that the supplied optional is not empty.static long
assertIsPresent(OptionalLong optional, String message)
Asserts that the supplied optional is not empty.static long
assertIsPresent(OptionalLong optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.
-
-
-
Method Detail
-
assertIsPresent
public static <T> T assertIsPresent(Optional<T> optional)
Asserts that the supplied optional is not empty.- Type Parameters:
T
- The optional value type.- Parameters:
optional
- The optional to check.- Returns:
- The optional's value.
-
assertIsPresent
public static <T> T assertIsPresent(Optional<T> optional, String message)
Asserts that the supplied optional is not empty.- Type Parameters:
T
- The optional value type.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.- Returns:
- The optional's value.
-
assertIsPresent
public static <T> T assertIsPresent(Optional<T> optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.- Type Parameters:
T
- The optional value type.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.- Returns:
- The optional's value.
-
assertIsPresent
public static int assertIsPresent(OptionalInt optional)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.- Returns:
- The optional's value.
-
assertIsPresent
public static int assertIsPresent(OptionalInt optional, String message)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.- Returns:
- The optional's value.
-
assertIsPresent
public static int assertIsPresent(OptionalInt optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.- Returns:
- The optional's value.
-
assertIsPresent
public static long assertIsPresent(OptionalLong optional)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.- Returns:
- The optional's value.
-
assertIsPresent
public static long assertIsPresent(OptionalLong optional, String message)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.- Returns:
- The optional's value.
-
assertIsPresent
public static long assertIsPresent(OptionalLong optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.- Returns:
- The optional's value.
-
assertIsPresent
public static double assertIsPresent(OptionalDouble optional)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.- Returns:
- The optional's value.
-
assertIsPresent
public static double assertIsPresent(OptionalDouble optional, String message)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.- Returns:
- The optional's value.
-
assertIsPresent
public static double assertIsPresent(OptionalDouble optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is not empty.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.- Returns:
- The optional's value.
-
assertIsEmpty
public static void assertIsEmpty(Optional<?> optional)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.
-
assertIsEmpty
public static void assertIsEmpty(Optional<?> optional, String message)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.
-
assertIsEmpty
public static void assertIsEmpty(Optional<?> optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.
-
assertIsEmpty
public static void assertIsEmpty(OptionalInt optional)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.
-
assertIsEmpty
public static void assertIsEmpty(OptionalInt optional, String message)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.
-
assertIsEmpty
public static void assertIsEmpty(OptionalInt optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.
-
assertIsEmpty
public static void assertIsEmpty(OptionalLong optional)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.
-
assertIsEmpty
public static void assertIsEmpty(OptionalLong optional, String message)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.
-
assertIsEmpty
public static void assertIsEmpty(OptionalLong optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.
-
assertIsEmpty
public static void assertIsEmpty(OptionalDouble optional)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.
-
assertIsEmpty
public static void assertIsEmpty(OptionalDouble optional, String message)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.message
- The failure message to fail with.
-
assertIsEmpty
public static void assertIsEmpty(OptionalDouble optional, Supplier<String> messageSupplier)
Asserts that the supplied optional is empty.- Parameters:
optional
- The optional to check.messageSupplier
- The supplier for the failure message to fail with.
-
-