
com.github.aro_tech.extended_mockito.ExtendedMatchers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of extended-mockito Show documentation
Show all versions of extended-mockito Show documentation
Jar with Mockito as a mixin interface, plus extra features
/**
*
*/
package com.github.aro_tech.extended_mockito;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Stream;
import com.github.aro_tech.extended_mockito.util.StringUtil;
/**
* @author aro_tech
*
*/
public interface ExtendedMatchers extends MatchersMixin {
/**
* A matcher call which matches if an argument contains all the given text
*
* @param expectedParts
* @return true if all the expected parts match
*/
default String containsAllOf(final CharSequence... expectedParts) {
return argThat((argument) -> StringUtil.containsAll(argument, expectedParts));
}
/**
* A matcher call which matches if an argument's toString() result contains
* all of the given text
*
* @param expectedParts
* @return true if all of the expected parts match, false if one does not
* match
*/
default T toStringContainsAllOf(final CharSequence... expectedParts) {
return argThat((argument) -> StringUtil.containsAll(argument, expectedParts));
}
/**
* A matcher call which matches if an argument contains at least one of the
* given text parts
*
* @param expectedParts
* @return true if any of the expected parts match, false if none match
*/
default String containsOneOrMoreOf(final CharSequence... expectedParts) {
return argThat((argument) -> StringUtil.containsOneOrMoreOf(argument, expectedParts));
}
/**
* A matcher call which matches if an argument's toString() result contains
* at least one of the given text
*
* @param expectedParts
* @return true if any of the expected parts match, false if none match
*/
default T toStringContainsOneOrMoreOf(final CharSequence... expectedParts) {
return argThat((argument) -> StringUtil.containsOneOrMoreOf(argument, expectedParts));
}
/**
* A predicate-based matcher for list arguments - all items must match
*
* @param predicate
* @return null
*/
default List allListItemsMatch(Predicate predicate) {
return argThat(new ListMatcher() {
@Override
protected boolean evaluateStream(Stream stream) {
return stream.allMatch(predicate);
}
});
}
/**
* A predicate-based matcher for list arguments - at least one item must
* match
*
* @param predicate
* A lambda to evaluate a method argument
* @return null
*/
default List oneOrMoreListItemsMatch(Predicate predicate) {
return argThat(new ListMatcher() {
@Override
protected boolean evaluateStream(Stream stream) {
return stream.anyMatch(predicate);
}
});
}
/**
* Lenient-order list matcher For a match, the list argument encountered by
* the mock must contain exactly the items provided (no more, no fewer), but
* any order is acceptable
*
* @param items
* List of exact items expected (in any order)
* @return null
*/
default List listContainsExactlyInAnyOrder(T... items) {
return argThat(new LenientOrderListMatcher<>(items));
}
/**
* Matcher for a map argument
*
* @param predicate
* lambda for assessing the map argument
* @return null
*/
default Map mapThat(Predicate
© 2015 - 2025 Weber Informatics LLC | Privacy Policy