Class CheckerSupplier<T>
- Type Parameters:
T
- the type of the result returned by theSupplier
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Supplier<T>,
CheckerSupplier<T>>, Supplier<T>>
A specialized checker for
Supplier
instances, providing a fluent API for validating
function behavior and results. This class allows assertions such as verifying that a function does not throw
exceptions, produces expected results, or returns non-null values for given inputs.
Example usage:
CheckerSupplier<Integer> checker = CheckerSupplier.check(() -> 5) .applyWithoutException() .producesExpected(5) .producesNonNull();
- See Also:
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerSupplier
(Supplier<T> supplier, String name) Constructs a newCheckerSupplier
with the specified supplier and name. -
Method Summary
Modifier and TypeMethodDescriptionAsserts that calling theget()
method of theSupplier
does not throw any exception.static <T> CheckerSupplier
<T> Creates a newCheckerSupplier
for the givenSupplier
instance with a default name.static <T> CheckerSupplier
<T> Creates a newCheckerSupplier
for the givenSupplier
instance with a custom name.producesExpected
(T expected) Asserts that theget()
method of theSupplier
produces the expected result.Asserts that theget()
method of theSupplier
produces a non-null result.protected CheckerSupplier
<T> self()
Returns this checker instance (for fluent API usage).Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerSupplier
-
-
Method Details
-
check
Creates a newCheckerSupplier
for the givenSupplier
instance with a custom name.- Type Parameters:
T
- the type of results supplied by theSupplier
- Parameters:
supplier
- theSupplier
instance to be checkedname
- the name to identify this checker instance (useful for error messages)- Returns:
- a new
CheckerSupplier
for the providedSupplier
-
check
Creates a newCheckerSupplier
for the givenSupplier
instance with a default name.- Type Parameters:
T
- the type of results supplied by theSupplier
- Parameters:
supplier
- theSupplier
instance to be checked- Returns:
- a new
CheckerSupplier
for the providedSupplier
-
self
Returns this checker instance (for fluent API usage).- Specified by:
self
in classAbstractChecker<Supplier<T>,
CheckerSupplier<T>> - Returns:
- this
CheckerSupplier
instance
-
applyWithoutException
Asserts that calling theget()
method of theSupplier
does not throw any exception.- Returns:
- this
CheckerSupplier
instance for further validation
-
producesExpected
Asserts that theget()
method of theSupplier
produces the expected result.- Parameters:
expected
- the expected result to compare with the actual result ofget()
- Returns:
- this
CheckerSupplier
instance for further validation
-
producesNonNull
Asserts that theget()
method of theSupplier
produces a non-null result.- Returns:
- this
CheckerSupplier
instance for further validation
-