mock context can be null

This commit is contained in:
金戟 2021-02-15 14:39:43 +08:00
parent 790409a336
commit 2a54fe70dd
2 changed files with 6 additions and 1 deletions

View File

@ -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) {

View File

@ -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;
}
}