mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-09 20:00:21 +08:00
thread mark not actually needed
This commit is contained in:
parent
705ba796f1
commit
d626906d28
@ -15,10 +15,6 @@ public class TestableUtil {
|
||||
* [0]Thread.getStackTrace() → [1]previousStackLocation() → [2]Invoker -> [3]Caller of invoker
|
||||
*/
|
||||
private static final int INDEX_OF_CALLER_METHOD = 3;
|
||||
/**
|
||||
* Just a special number to identify test worker thread
|
||||
*/
|
||||
private static final int TEST_WORKER_THREAD_PRIORITY = 55555;
|
||||
|
||||
/**
|
||||
* Get the last visit method in source file
|
||||
@ -38,19 +34,10 @@ public class TestableUtil {
|
||||
String testCaseName = findFirstMethodFromTestClass(testClassName, Thread.currentThread().getStackTrace());
|
||||
if (testCaseName.isEmpty()) {
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
// try find previously marked thread
|
||||
Thread testWorkerThread = findTestWorkerThread(threads);
|
||||
if (testWorkerThread != null) {
|
||||
testCaseName = findFirstMethodFromTestClass(testClassName, testWorkerThread.getStackTrace());
|
||||
if (!testCaseName.isEmpty()) {
|
||||
return testCaseName;
|
||||
}
|
||||
}
|
||||
// travel all possible threads
|
||||
for (Thread t : threads) {
|
||||
testCaseName = findFirstMethodFromTestClass(testClassName, t.getStackTrace());
|
||||
if (!testCaseName.isEmpty()) {
|
||||
t.setPriority(TEST_WORKER_THREAD_PRIORITY);
|
||||
return testCaseName;
|
||||
}
|
||||
}
|
||||
@ -67,15 +54,6 @@ public class TestableUtil {
|
||||
return stack.getFileName() + ":" + stack.getLineNumber();
|
||||
}
|
||||
|
||||
private static Thread findTestWorkerThread(Set<Thread> threads) {
|
||||
for (Thread t : threads) {
|
||||
if (t.getPriority() == TEST_WORKER_THREAD_PRIORITY) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String findFirstMethodFromTestClass(String testClassName, StackTraceElement[] stack) {
|
||||
for (int i = stack.length - 1; i >= 0; i--) {
|
||||
if (getOuterClassName(stack[i].getClassName()).equals(testClassName)) {
|
||||
|
Loading…
Reference in New Issue
Block a user