org.mockito.internal.creation.bytebuddy.StackTraceChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-core Show documentation
Show all versions of mockito-core Show documentation
Mockito mock objects library core API and implementation
/*
* Copyright (c) 2022 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.creation.bytebuddy;
import java.util.function.Predicate;
class StackTraceChecker implements Predicate> {
@Override
public boolean test(Class type) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (int index = 1; index < stackTrace.length - 1; index++) {
if (!stackTrace[index].getClassName().startsWith("org.mockito.internal.")) {
if (stackTrace[index + 1].getMethodName().startsWith("")) {
try {
if (!stackTrace[index + 1].getClassName().equals(type.getName())
&& type.isAssignableFrom(
Class.forName(
stackTrace[index + 1].getClassName(),
false,
type.getClassLoader()))) {
return true;
} else {
break;
}
} catch (ClassNotFoundException ignored) {
break;
}
}
}
}
return false;
}
}