Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.github.alkedr.matchers.reporting.ReportingMatchers Maven / Gradle / Ivy
package com.github.alkedr.matchers.reporting;
import com.github.alkedr.matchers.reporting.sub.value.checkers.SubValuesChecker;
import com.github.alkedr.matchers.reporting.sub.value.extractors.SubValuesExtractor;
import com.github.alkedr.matchers.reporting.sub.value.extractors.SubValuesExtractors;
import org.hamcrest.Matcher;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.function.Supplier;
import static com.github.alkedr.matchers.reporting.sub.value.checkers.SubValueCheckers.compositeSubValuesCheckerSupplier;
import static com.github.alkedr.matchers.reporting.sub.value.checkers.SubValueCheckers.matcherSubValuesChecker;
import static com.github.alkedr.matchers.reporting.sub.value.checkers.SubValueCheckers.noOpSubValuesChecker;
import static com.github.alkedr.matchers.reporting.sub.value.extractors.SubValuesExtractors.*;
import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.equalTo;
// используй static import
public enum ReportingMatchers {
;
// TODO: unchecked() ?
public static ReportingMatcher noOp() {
//noinspection unchecked
return (ReportingMatcher) NoOpMatcher.INSTANCE;
}
// оборачивает переданный ему матчер если он не reporting.
public static ReportingMatcher toReportingMatcher(Matcher matcher) {
return matcher instanceof ReportingMatcher ? (ReportingMatcher) matcher : new ReportingMatcherAdapter<>(matcher);
}
public static Iterable> toReportingMatchers(Iterable extends Matcher super U>> matchers) {
// TODO: конвертировать на лету?
Collection> result = new ArrayList<>();
for (Matcher super U> matcher : matchers) {
result.add(toReportingMatcher(matcher));
}
return result;
}
@SafeVarargs
public static ReportingMatcher sequence(ReportingMatcher super T>... matchers) {
return sequence(asList(matchers));
}
public static ReportingMatcher sequence(Iterable extends ReportingMatcher super T>> matchers) {
return new SequenceMatcher<>(matchers);
}
@SafeVarargs
public static ReportingMatcher merge(ReportingMatcher super T>... matchers) {
return merge(asList(matchers));
}
public static ReportingMatcher merge(Iterable extends ReportingMatcher super T>> matchers) {
return new MergingMatcher<>(sequence(matchers));
}
public static ReportingMatcher present() {
//noinspection unchecked
return (ReportingMatcher) PresentMatcher.INSTANCE;
}
public static ReportingMatcher absent() {
//noinspection unchecked
return (ReportingMatcher) AbsentMatcher.INSTANCE;
}
public static ReportingMatcher value(SubValuesExtractor subValuesExtractor, S value) {
return value(subValuesExtractor, equalTo(value));
}
public static ReportingMatcher value(SubValuesExtractor subValuesExtractor, Matcher super S> matcher) {
return value(subValuesExtractor, toReportingMatcher(matcher));
}
public static ReportingMatcher value(SubValuesExtractor subValuesExtractor, ReportingMatcher super S> reportingMatcher) {
return subValuesMatcher(subValuesExtractor, matcherSubValuesChecker(reportingMatcher));
}
@SafeVarargs // TODO: требовать наличия хотя бы одного матчера!
public static ReportingMatcher value(SubValuesExtractor subValuesExtractor, Matcher super S>... matchers) {
return value(subValuesExtractor, asList(matchers));
}
public static ReportingMatcher value(SubValuesExtractor subValuesExtractor, Iterable extends Matcher super S>> matchers) {
return value(subValuesExtractor, merge(toReportingMatchers(matchers)));
}
public static ReportingMatcher value(String nameForReport, SubValuesExtractor subValuesExtractor, S value) {
return value(renamed(subValuesExtractor, nameForReport), value);
}
public static ReportingMatcher value(String nameForReport, SubValuesExtractor subValuesExtractor, Matcher super S> matcher) {
return value(renamed(subValuesExtractor, nameForReport), matcher);
}
public static ReportingMatcher value(String nameForReport, SubValuesExtractor subValuesExtractor, ReportingMatcher super S> reportingMatcher) {
return value(renamed(subValuesExtractor, nameForReport), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher value(String nameForReport, SubValuesExtractor subValuesExtractor, Matcher super S>... matchers) {
return value(renamed(subValuesExtractor, nameForReport), matchers);
}
public static ReportingMatcher value(String nameForReport, SubValuesExtractor subValuesExtractor, Iterable extends Matcher super S>> matchers) {
return value(renamed(subValuesExtractor, nameForReport), matchers);
}
public static ReportingMatcher field(Field field, S value) {
return value(SubValuesExtractors.field(field), value);
}
public static ReportingMatcher field(Field field, Matcher super S> matcher) {
return value(SubValuesExtractors.field(field), matcher);
}
public static ReportingMatcher field(Field field, ReportingMatcher super S> reportingMatcher) {
return value(SubValuesExtractors.field(field), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher field(Field field, Matcher super S>... matchers) {
return value(SubValuesExtractors.field(field), matchers);
}
public static ReportingMatcher field(Field field, Iterable extends Matcher super S>> matchers) {
return value(SubValuesExtractors.field(field), matchers);
}
public static ReportingMatcher field(String fieldName, S value) {
return value(SubValuesExtractors.fieldByName(fieldName), value);
}
public static ReportingMatcher field(String fieldName, Matcher super S> matcher) {
return value(SubValuesExtractors.fieldByName(fieldName), matcher);
}
public static ReportingMatcher field(String fieldName, ReportingMatcher super S> reportingMatcher) {
return value(SubValuesExtractors.fieldByName(fieldName), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher field(String fieldName, Matcher super S>... matchers) {
return value(SubValuesExtractors.fieldByName(fieldName), matchers);
}
public static ReportingMatcher field(String fieldName, Iterable extends Matcher super S>> matchers) {
return value(SubValuesExtractors.fieldByName(fieldName), matchers);
}
public static ReportingMatcher field(String nameForReport, Field field, S value) {
return value(nameForReport, SubValuesExtractors.field(field), value);
}
public static ReportingMatcher field(String nameForReport, Field field, Matcher super S> matcher) {
return value(nameForReport, SubValuesExtractors.field(field), matcher);
}
public static ReportingMatcher field(String nameForReport, Field field, ReportingMatcher super S> reportingMatcher) {
return value(nameForReport, SubValuesExtractors.field(field), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher field(String nameForReport, Field field, Matcher super S>... matchers) {
return value(nameForReport, SubValuesExtractors.field(field), matchers);
}
public static ReportingMatcher field(String nameForReport, Field field, Iterable extends Matcher super S>> matchers) {
return value(nameForReport, SubValuesExtractors.field(field), matchers);
}
public static ReportingMatcher field(String nameForReport, String fieldName, S value) {
return value(nameForReport, SubValuesExtractors.fieldByName(fieldName), value);
}
public static ReportingMatcher field(String nameForReport, String fieldName, Matcher super S> matcher) {
return value(nameForReport, SubValuesExtractors.fieldByName(fieldName), matcher);
}
public static ReportingMatcher field(String nameForReport, String fieldName, ReportingMatcher super S> reportingMatcher) {
return value(nameForReport, SubValuesExtractors.fieldByName(fieldName), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher field(String nameForReport, String fieldName, Matcher super S>... matchers) {
return value(nameForReport, SubValuesExtractors.fieldByName(fieldName), matchers);
}
public static ReportingMatcher field(String nameForReport, String fieldName, Iterable extends Matcher super S>> matchers) {
return value(nameForReport, SubValuesExtractors.fieldByName(fieldName), matchers);
}
public static ReportingMatcher method(MethodInvocation invocation, S value) {
return value(SubValuesExtractors.method(invocation.method, invocation.arguments), value);
}
public static ReportingMatcher method(MethodInvocation invocation, Matcher super S> matcher) {
return value(SubValuesExtractors.method(invocation.method, invocation.arguments), matcher);
}
public static ReportingMatcher method(MethodInvocation invocation, ReportingMatcher super S> reportingMatcher) {
return value(SubValuesExtractors.method(invocation.method, invocation.arguments), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher method(MethodInvocation invocation, Matcher super S>... matchers) {
return value(SubValuesExtractors.method(invocation.method, invocation.arguments), matchers);
}
public static ReportingMatcher method(MethodInvocation invocation, Iterable extends Matcher super S>> matchers) {
return value(SubValuesExtractors.method(invocation.method, invocation.arguments), matchers);
}
public static ReportingMatcher method(MethodByNameInvocation invocation, S value) {
return value(SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), value);
}
public static ReportingMatcher method(MethodByNameInvocation invocation, Matcher super S> matcher) {
return value(SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), matcher);
}
public static ReportingMatcher method(MethodByNameInvocation invocation, ReportingMatcher super S> reportingMatcher) {
return value(SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher method(MethodByNameInvocation invocation, Matcher super S>... matchers) {
return value(SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), matchers);
}
public static ReportingMatcher method(MethodByNameInvocation invocation, Iterable extends Matcher super S>> matchers) {
return value(SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), matchers);
}
public static ReportingMatcher method(String nameForReport, MethodInvocation invocation, S value) {
return value(nameForReport, SubValuesExtractors.method(invocation.method, invocation.arguments), value);
}
public static ReportingMatcher method(String nameForReport, MethodInvocation invocation, Matcher super S> matcher) {
return value(nameForReport, SubValuesExtractors.method(invocation.method, invocation.arguments), matcher);
}
public static ReportingMatcher method(String nameForReport, MethodInvocation invocation, ReportingMatcher super S> reportingMatcher) {
return value(nameForReport, SubValuesExtractors.method(invocation.method, invocation.arguments), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher method(String nameForReport, MethodInvocation invocation, Matcher super S>... matchers) {
return value(nameForReport, SubValuesExtractors.method(invocation.method, invocation.arguments), matchers);
}
public static ReportingMatcher method(String nameForReport, MethodInvocation invocation, Iterable extends Matcher super S>> matchers) {
return value(nameForReport, SubValuesExtractors.method(invocation.method, invocation.arguments), matchers);
}
public static ReportingMatcher method(String nameForReport, MethodByNameInvocation invocation, S value) {
return value(nameForReport, SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), value);
}
public static ReportingMatcher method(String nameForReport, MethodByNameInvocation invocation, Matcher super S> matcher) {
return value(nameForReport, SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), matcher);
}
public static ReportingMatcher method(String nameForReport, MethodByNameInvocation invocation, ReportingMatcher super S> reportingMatcher) {
return value(nameForReport, SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher method(String nameForReport, MethodByNameInvocation invocation, Matcher super S>... matchers) {
return value(nameForReport, SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), matchers);
}
public static ReportingMatcher method(String nameForReport, MethodByNameInvocation invocation, Iterable extends Matcher super S>> matchers) {
return value(nameForReport, SubValuesExtractors.methodByName(invocation.methodName, invocation.arguments), matchers);
}
public static MethodInvocation invocation(Method method, Object... arguments) {
return new MethodInvocation(method, arguments);
}
public static MethodByNameInvocation invocation(String methodName, Object... arguments) {
return new MethodByNameInvocation(methodName, arguments);
}
public static ReportingMatcher getter(Method method, S value) {
return value(SubValuesExtractors.getter(method), value);
}
public static ReportingMatcher getter(Method method, Matcher super S> matcher) {
return value(SubValuesExtractors.getter(method), matcher);
}
public static ReportingMatcher getter(Method method, ReportingMatcher super S> reportingMatcher) {
return value(SubValuesExtractors.getter(method), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher getter(Method method, Matcher super S>... matchers) {
return value(SubValuesExtractors.getter(method), matchers);
}
public static ReportingMatcher getter(Method method, Iterable extends Matcher super S>> matchers) {
return value(SubValuesExtractors.getter(method), matchers);
}
public static ReportingMatcher getter(String methodName, S value) {
return value(SubValuesExtractors.getterByName(methodName), value);
}
public static ReportingMatcher getter(String methodName, Matcher super S> matcher) {
return value(SubValuesExtractors.getterByName(methodName), matcher);
}
public static ReportingMatcher getter(String methodName, ReportingMatcher super S> reportingMatcher) {
return value(SubValuesExtractors.getterByName(methodName), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher getter(String methodName, Matcher super S>... matchers) {
return value(SubValuesExtractors.getterByName(methodName), matchers);
}
public static ReportingMatcher getter(String methodName, Iterable extends Matcher super S>> matchers) {
return value(SubValuesExtractors.getterByName(methodName), matchers);
}
public static ReportingMatcher arrayElement(int index, T value) {
return value(SubValuesExtractors.arrayElement(index), value);
}
public static ReportingMatcher arrayElement(int index, Matcher super T> matcher) {
return value(SubValuesExtractors.arrayElement(index), matcher);
}
public static ReportingMatcher arrayElement(int index, ReportingMatcher super T> reportingMatcher) {
return value(SubValuesExtractors.arrayElement(index), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher arrayElement(int index, Matcher super T>... matchers) {
return value(SubValuesExtractors.arrayElement(index), matchers);
}
public static ReportingMatcher arrayElement(int index, Iterable extends Matcher super T>> matchers) {
return value(SubValuesExtractors.arrayElement(index), matchers);
}
public static ReportingMatcher> iterableElement(int index, T value) {
return value(SubValuesExtractors.iterableElement(index), value);
}
public static ReportingMatcher> iterableElement(int index, Matcher super T> matcher) {
return value(SubValuesExtractors.iterableElement(index), matcher);
}
public static ReportingMatcher> iterableElement(int index, ReportingMatcher super T> reportingMatcher) {
return value(SubValuesExtractors.iterableElement(index), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher> iterableElement(int index, Matcher super T>... matchers) {
return value(SubValuesExtractors.iterableElement(index), matchers);
}
public static ReportingMatcher> iterableElement(int index, Iterable extends Matcher super T>> matchers) {
return value(SubValuesExtractors.iterableElement(index), matchers);
}
public static ReportingMatcher> listElement(int index, T value) {
return value(SubValuesExtractors.listElement(index), value);
}
public static ReportingMatcher> listElement(int index, Matcher super T> matcher) {
return value(SubValuesExtractors.listElement(index), matcher);
}
public static ReportingMatcher> listElement(int index, ReportingMatcher super T> reportingMatcher) {
return value(SubValuesExtractors.listElement(index), reportingMatcher);
}
@SafeVarargs
public static ReportingMatcher> listElement(int index, Matcher super T>... matchers) {
return value(SubValuesExtractors.listElement(index), matchers);
}
public static ReportingMatcher> listElement(int index, Iterable extends Matcher super T>> matchers) {
return value(SubValuesExtractors.listElement(index), matchers);
}
public static ReportingMatcher