mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-02-04 08:40:20 +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) {
|
public static String currentTestCaseName(Object testClassRef) {
|
||||||
|
return currentTestCaseName(testClassRef.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String currentTestCaseName(Class testClass) {
|
||||||
StackTraceElement[] stack = getMainThread().getStackTrace();
|
StackTraceElement[] stack = getMainThread().getStackTrace();
|
||||||
String testClassName = testClassRef.getClass().getName();
|
String testClassName = getRealClassName(testClass);
|
||||||
for (int i = stack.length - 1; i >= 0; i--) {
|
for (int i = stack.length - 1; i >= 0; i--) {
|
||||||
if (stack[i].getClassName().equals(testClassName)) {
|
if (stack[i].getClassName().equals(testClassName)) {
|
||||||
return stack[i].getMethodName();
|
return stack[i].getMethodName();
|
||||||
@ -28,6 +32,12 @@ public class TestableUtil {
|
|||||||
return "";
|
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() {
|
private static Thread getMainThread() {
|
||||||
for (Thread t : Thread.getAllStackTraces().keySet()) {
|
for (Thread t : Thread.getAllStackTraces().keySet()) {
|
||||||
if (t.getId() == 1L) {
|
if (t.getId() == 1L) {
|
||||||
|
Loading…
Reference in New Issue
Block a user