Class CheckerSet<T>
- Type Parameters:
T
- the type of elements in the set
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Set<T>,
CheckerSet<T>>, Set<T>>
A specialized checker for
Set
collections, providing fluent assertion methods
for validating set properties and contents.
This class extends AbstractChecker
and offers a variety of checks such as emptiness,
subset/superset relationships, and element matching based on predicates.
Example usage: Set<String> mySet = Set.of("a", "b", "c"); CheckerSet.check(mySet).isSuperset(List.of("a")).isEmpty();
- See Also:
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerSet
(Set<T> set, String name) Constructs a newCheckerSet
with the specified set and name. -
Method Summary
Modifier and TypeMethodDescriptionChecks if all elements in the set match the given predicate.Checks if any element in the set matches the given predicate.static <T> CheckerSet
<T> Creates a CheckerSet for the given set with a default name.static <T> CheckerSet
<T> Creates a CheckerSet for the given set and assigns a custom name.isEmpty()
Checks if the set is empty.isSubset
(Collection<T> collection) Checks if the set is a subset of the given collection.isSufficientPercentage
(Predicate<T> matching, double percentage) Checks if at least the specified percentage of elements in the set match the given predicate.isSuperset
(Collection<T> collection) Checks if the set is a superset of the given collection.protected CheckerSet
<T> self()
Returns this instance (for fluent API).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
-
CheckerSet
-
-
Method Details
-
check
Creates a CheckerSet for the given set and assigns a custom name.- Type Parameters:
T
- theSet
's element type- Parameters:
set
- the set to checkname
- the name to assign to this checker- Returns:
- a CheckerSet instance for the given set
-
check
Creates a CheckerSet for the given set with a default name.- Type Parameters:
T
- theSet
's element type- Parameters:
set
- the set to check- Returns:
- a CheckerSet instance for the given set
-
self
Returns this instance (for fluent API).- Specified by:
self
in classAbstractChecker<Set<T>,
CheckerSet<T>> - Returns:
- this CheckerSet instance
-
isEmpty
-
anyMatch
Checks if any element in the set matches the given predicate.- Parameters:
predicate
- the condition to test elements- Returns:
- this CheckerSet instance
-
allMatch
Checks if all elements in the set match the given predicate.- Parameters:
predicate
- the condition to test elements- Returns:
- this CheckerSet instance
-
isSubset
Checks if the set is a subset of the given collection.- Parameters:
collection
- the collection to compare with- Returns:
- this CheckerSet instance
-
isSuperset
Checks if the set is a superset of the given collection.- Parameters:
collection
- the collection to compare with- Returns:
- this CheckerSet instance
-
isSufficientPercentage
Checks if at least the specified percentage of elements in the set match the given predicate.- Parameters:
matching
- the condition to test elementspercentage
- the minimum percentage (0-100) of elements that must match- Returns:
- this CheckerSet instance
-