mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-03-13 11:20:32 +08:00
mock context can be null
This commit is contained in:
parent
790409a336
commit
2a54fe70dd
@ -22,6 +22,10 @@ public class InvokeRecordUtil {
|
||||
StackTraceElement mockMethodTraceElement = Thread.currentThread().getStackTrace()[INDEX_OF_TEST_CLASS];
|
||||
String mockMethodName = mockMethodTraceElement.getMethodName();
|
||||
MockContext mockContext = MockContextUtil.context.get();
|
||||
if (mockContext == null) {
|
||||
// mock method not invoked from test case, e.g. in static block
|
||||
return;
|
||||
}
|
||||
String testClass = mockContext.testClassName;
|
||||
String testCaseName = mockContext.testCaseName;
|
||||
if (isConstructor) {
|
||||
|
@ -36,7 +36,8 @@ public class MockContextUtil {
|
||||
}
|
||||
|
||||
public static Map<String, Object> parameters() {
|
||||
return MockContextUtil.context.get().parameters;
|
||||
MockContext mockContext = MockContextUtil.context.get();
|
||||
return mockContext == null ? new HashMap<String, Object>() : mockContext.parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user