mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-25 11:51:15 +08:00
handle inner class correctly
This commit is contained in:
parent
9e1c1b8c3b
commit
2f6c2105f6
@ -18,8 +18,12 @@ public class TestableUtil {
|
||||
}
|
||||
|
||||
public static String currentTestCaseName(Object testClassRef) {
|
||||
return currentTestCaseName(testClassRef.getClass());
|
||||
}
|
||||
|
||||
public static String currentTestCaseName(Class testClass) {
|
||||
StackTraceElement[] stack = getMainThread().getStackTrace();
|
||||
String testClassName = testClassRef.getClass().getName();
|
||||
String testClassName = getRealClassName(testClass);
|
||||
for (int i = stack.length - 1; i >= 0; i--) {
|
||||
if (stack[i].getClassName().equals(testClassName)) {
|
||||
return stack[i].getMethodName();
|
||||
@ -28,6 +32,12 @@ public class TestableUtil {
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String getRealClassName(Class testClass) {
|
||||
String className = testClass.getName();
|
||||
int posOfInnerClass = className.lastIndexOf('$');
|
||||
return posOfInnerClass > 0 ? className.substring(0, posOfInnerClass) : className;
|
||||
}
|
||||
|
||||
private static Thread getMainThread() {
|
||||
for (Thread t : Thread.getAllStackTraces().keySet()) {
|
||||
if (t.getId() == 1L) {
|
||||
|
Loading…
Reference in New Issue
Block a user