|
|
|
|
@@ -120,7 +120,7 @@ import org.springframework.util.ReflectionUtils;
|
|
|
|
|
* Locate a method by invoking it through a proxy of the target handler:
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* ResolvableMethod.on(TestController.class).mockCall(o -> o.handle(null)).method();
|
|
|
|
|
* ResolvableMethod.on(TestController.class).mockCall((o) -> o.handle(null)).method();
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* @author Rossen Stoyanchev
|
|
|
|
|
@@ -323,7 +323,7 @@ public final class ResolvableMethod {
|
|
|
|
|
* Filter on methods with the given name.
|
|
|
|
|
*/
|
|
|
|
|
public Builder<T> named(String methodName) {
|
|
|
|
|
addFilter("methodName=" + methodName, method -> method.getName().equals(methodName));
|
|
|
|
|
addFilter("methodName=" + methodName, (method) -> method.getName().equals(methodName));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -331,7 +331,7 @@ public final class ResolvableMethod {
|
|
|
|
|
* Filter on methods with the given parameter types.
|
|
|
|
|
*/
|
|
|
|
|
public Builder<T> argTypes(Class<?>... argTypes) {
|
|
|
|
|
addFilter("argTypes=" + Arrays.toString(argTypes), method -> ObjectUtils.isEmpty(argTypes)
|
|
|
|
|
addFilter("argTypes=" + Arrays.toString(argTypes), (method) -> ObjectUtils.isEmpty(argTypes)
|
|
|
|
|
? method.getParameterCount() == 0 : Arrays.equals(method.getParameterTypes(), argTypes));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
@@ -354,8 +354,8 @@ public final class ResolvableMethod {
|
|
|
|
|
@SafeVarargs
|
|
|
|
|
public final Builder<T> annotPresent(Class<? extends Annotation>... annotationTypes) {
|
|
|
|
|
String message = "annotationPresent=" + Arrays.toString(annotationTypes);
|
|
|
|
|
addFilter(message, candidate -> Arrays.stream(annotationTypes)
|
|
|
|
|
.allMatch(annotType -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null));
|
|
|
|
|
addFilter(message, (candidate) -> Arrays.stream(annotationTypes)
|
|
|
|
|
.allMatch((annotType) -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -365,10 +365,10 @@ public final class ResolvableMethod {
|
|
|
|
|
@SafeVarargs
|
|
|
|
|
public final Builder<T> annotNotPresent(Class<? extends Annotation>... annotationTypes) {
|
|
|
|
|
String message = "annotationNotPresent=" + Arrays.toString(annotationTypes);
|
|
|
|
|
addFilter(message, candidate -> {
|
|
|
|
|
addFilter(message, (candidate) -> {
|
|
|
|
|
if (annotationTypes.length != 0) {
|
|
|
|
|
return Arrays.stream(annotationTypes).noneMatch(
|
|
|
|
|
annotType -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null);
|
|
|
|
|
(annotType) -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return candidate.getAnnotations().length == 0;
|
|
|
|
|
@@ -403,7 +403,7 @@ public final class ResolvableMethod {
|
|
|
|
|
public Builder<T> returning(ResolvableType returnType) {
|
|
|
|
|
String expected = returnType.toString();
|
|
|
|
|
String message = "returnType=" + expected;
|
|
|
|
|
addFilter(message, m -> expected.equals(ResolvableType.forMethodReturnType(m).toString()));
|
|
|
|
|
addFilter(message, (m) -> expected.equals(ResolvableType.forMethodReturnType(m).toString()));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -423,7 +423,7 @@ public final class ResolvableMethod {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isMatch(Method method) {
|
|
|
|
|
return this.filters.stream().allMatch(p -> p.test(method));
|
|
|
|
|
return this.filters.stream().allMatch((p) -> p.test(method));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String formatMethods(Set<Method> methods) {
|
|
|
|
|
@@ -581,7 +581,7 @@ public final class ResolvableMethod {
|
|
|
|
|
*/
|
|
|
|
|
@SafeVarargs
|
|
|
|
|
public final ArgResolver annotPresent(Class<? extends Annotation>... annotationTypes) {
|
|
|
|
|
this.filters.add(param -> Arrays.stream(annotationTypes).allMatch(param::hasParameterAnnotation));
|
|
|
|
|
this.filters.add((param) -> Arrays.stream(annotationTypes).allMatch(param::hasParameterAnnotation));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -591,7 +591,7 @@ public final class ResolvableMethod {
|
|
|
|
|
*/
|
|
|
|
|
@SafeVarargs
|
|
|
|
|
public final ArgResolver annotNotPresent(Class<? extends Annotation>... annotationTypes) {
|
|
|
|
|
this.filters.add(param -> (annotationTypes.length > 0
|
|
|
|
|
this.filters.add((param) -> (annotationTypes.length > 0
|
|
|
|
|
? Arrays.stream(annotationTypes).noneMatch(param::hasParameterAnnotation)
|
|
|
|
|
: param.getParameterAnnotations().length == 0));
|
|
|
|
|
return this;
|
|
|
|
|
@@ -618,7 +618,7 @@ public final class ResolvableMethod {
|
|
|
|
|
* @param type the expected type
|
|
|
|
|
*/
|
|
|
|
|
public MethodParameter arg(ResolvableType type) {
|
|
|
|
|
this.filters.add(p -> type.toString().equals(ResolvableType.forMethodParameter(p).toString()));
|
|
|
|
|
this.filters.add((p) -> type.toString().equals(ResolvableType.forMethodParameter(p).toString()));
|
|
|
|
|
return arg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -638,7 +638,7 @@ public final class ResolvableMethod {
|
|
|
|
|
for (int i = 0; i < ResolvableMethod.this.method.getParameterCount(); i++) {
|
|
|
|
|
MethodParameter param = new SynthesizingMethodParameter(ResolvableMethod.this.method, i);
|
|
|
|
|
param.initParameterNameDiscovery(nameDiscoverer);
|
|
|
|
|
if (this.filters.stream().allMatch(p -> p.test(param))) {
|
|
|
|
|
if (this.filters.stream().allMatch((p) -> p.test(param))) {
|
|
|
|
|
matches.add(param);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|