mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-11 04:40:12 +08:00
mock target is always in parameter when recording
This commit is contained in:
parent
02c74299f4
commit
b4a29e7e8e
@ -25,7 +25,7 @@ public class MockClassHandler extends BaseClassWithContextHandler {
|
|||||||
private static final String SIGNATURE_INVOKE_ORIGIN =
|
private static final String SIGNATURE_INVOKE_ORIGIN =
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;";
|
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;";
|
||||||
private static final String METHOD_RECORD_MOCK_INVOKE = "recordMockInvoke";
|
private static final String METHOD_RECORD_MOCK_INVOKE = "recordMockInvoke";
|
||||||
private static final String SIGNATURE_RECORDER_METHOD_INVOKE = "([Ljava/lang/Object;ZZ)V";
|
private static final String SIGNATURE_RECORDER_METHOD_INVOKE = "([Ljava/lang/Object;Z)V";
|
||||||
private static final String METHOD_IS_ASSOCIATED = "isAssociated";
|
private static final String METHOD_IS_ASSOCIATED = "isAssociated";
|
||||||
private static final String SIGNATURE_IS_ASSOCIATED = "()Z";
|
private static final String SIGNATURE_IS_ASSOCIATED = "()Z";
|
||||||
|
|
||||||
@ -188,7 +188,6 @@ public class MockClassHandler extends BaseClassWithContextHandler {
|
|||||||
} else {
|
} else {
|
||||||
il.add(new InsnNode(ICONST_0));
|
il.add(new InsnNode(ICONST_0));
|
||||||
}
|
}
|
||||||
il.add(new InsnNode(ICONST_1));
|
|
||||||
il.add(new MethodInsnNode(INVOKESTATIC, CLASS_INVOKE_RECORD_UTIL, METHOD_RECORD_MOCK_INVOKE,
|
il.add(new MethodInsnNode(INVOKESTATIC, CLASS_INVOKE_RECORD_UTIL, METHOD_RECORD_MOCK_INVOKE,
|
||||||
SIGNATURE_RECORDER_METHOD_INVOKE, false));
|
SIGNATURE_RECORDER_METHOD_INVOKE, false));
|
||||||
mn.instructions.insertBefore(mn.instructions.getFirst(), il);
|
mn.instructions.insertBefore(mn.instructions.getFirst(), il);
|
||||||
|
@ -16,9 +16,8 @@ public class InvokeRecordUtil {
|
|||||||
* Record mock method invoke event
|
* Record mock method invoke event
|
||||||
* @param args invocation parameters
|
* @param args invocation parameters
|
||||||
* @param isConstructor whether mocked method is constructor
|
* @param isConstructor whether mocked method is constructor
|
||||||
* @param isTargetClassInParameter whether use first parameter as target class
|
|
||||||
*/
|
*/
|
||||||
public static void recordMockInvoke(Object[] args, boolean isConstructor, boolean isTargetClassInParameter) {
|
public static void recordMockInvoke(Object[] args, boolean isConstructor) {
|
||||||
StackTraceElement mockMethodTraceElement = Thread.currentThread().getStackTrace()[INDEX_OF_TEST_CLASS];
|
StackTraceElement mockMethodTraceElement = Thread.currentThread().getStackTrace()[INDEX_OF_TEST_CLASS];
|
||||||
String mockMethodName = mockMethodTraceElement.getMethodName();
|
String mockMethodName = mockMethodTraceElement.getMethodName();
|
||||||
MockContext mockContext = MockContextUtil.context.get();
|
MockContext mockContext = MockContextUtil.context.get();
|
||||||
@ -32,7 +31,7 @@ public class InvokeRecordUtil {
|
|||||||
mockContext.invokeRecord.get(mockMethodName).add(args);
|
mockContext.invokeRecord.get(mockMethodName).add(args);
|
||||||
LogUtil.verbose(" Mock constructor \"%s\" invoked in %s::%s", mockMethodName, testClass, testCaseName);
|
LogUtil.verbose(" Mock constructor \"%s\" invoked in %s::%s", mockMethodName, testClass, testCaseName);
|
||||||
} else {
|
} else {
|
||||||
mockContext.invokeRecord.get(mockMethodName).add(isTargetClassInParameter ? slice(args, 1) : args);
|
mockContext.invokeRecord.get(mockMethodName).add(slice(args, 1));
|
||||||
LogUtil.verbose(" Mock method \"%s\" invoked in %s::%s\"", mockMethodName, testClass, testCaseName);
|
LogUtil.verbose(" Mock method \"%s\" invoked in %s::%s\"", mockMethodName, testClass, testCaseName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user