imToken v2.14.1版本的 MD5 值为:83050b2c91219b46832c8336279e7878
以下内容为反编译后的 TypeSafeMatching.java 源代码,内容仅作参考
package org.mockito.internal.invocation;
import java.lang.reflect.Method;
import org.mockito.ArgumentMatcher;
public class TypeSafeMatching implements ArgumentMatcherAction {
private static final ArgumentMatcherAction TYPE_SAFE_MATCHING_ACTION = new TypeSafeMatching();
private TypeSafeMatching() {
}
public static ArgumentMatcherAction matchesTypeSafe() {
return TYPE_SAFE_MATCHING_ACTION;
}
@Override
public boolean apply(ArgumentMatcher argumentMatcher, Object obj) {
return isCompatible(argumentMatcher, obj) && argumentMatcher.matches(obj);
}
private static boolean isCompatible(ArgumentMatcher<?> argumentMatcher, Object obj) {
if (obj == null) {
return true;
}
return getArgumentType(argumentMatcher).isInstance(obj);
}
private static Class<?> getArgumentType(ArgumentMatcher<?> argumentMatcher) {
Method[] methods;
for (Method method : argumentMatcher.getClass().getMethods()) {
if (isMatchesMethod(method)) {
return method.getParameterTypes()[0];
}
}
throw new NoSuchMethodError("Method 'matches(T)' not found in ArgumentMatcher: " + argumentMatcher + " !\r\n Please file a bug with this stack trace at: https://github.com/mockito/mockito/issues/new ");
}
private static boolean isMatchesMethod(Method method) {
if (method.getParameterTypes().length == 1 && !method.isBridge()) {
return "matches".equals(method.getName());
}
return false;
}
}