remove unnecessary mock class reference in test class handler

This commit is contained in:
金戟 2021-03-26 22:26:12 +08:00
parent 20b346ed34
commit 55ccc385d5
3 changed files with 6 additions and 6 deletions

View File

@ -23,7 +23,6 @@ public class TestClassHandler extends BaseClassWithContextHandler {
private static final String METHOD_CLEAN = "clean";
private static final String DESC_METHOD_CLEAN = "()V";
private final String mockClassName;
private int testCaseCount = 0;
private final Framework[] frameworkClasses = new Framework[] {
@ -33,10 +32,6 @@ public class TestClassHandler extends BaseClassWithContextHandler {
new TestNgOnClassFramework()
};
public TestClassHandler(String mockClassName) {
this.mockClassName = mockClassName;
}
/**
* Handle bytecode of test class
* @param cn original class node

View File

@ -66,7 +66,7 @@ public class TestableClassTransformer implements ClassFileTransformer {
if (mockClass != null) {
// it's a test class with testable enabled
LogUtil.diagnose("Handling test class %s", className);
bytes = new TestClassHandler(mockClass).getBytes(bytes);
bytes = new TestClassHandler().getBytes(bytes);
dumpByte(className, bytes);
} else {
mockClass = foundMockForSourceClass(className);

View File

@ -23,6 +23,7 @@ public class MockAssociationUtil {
public static Map<String, Set<String>> mockToTests = UnnullableMap.of(new HashSet<String>());
/**
* Note: this method will be invoked in transformed byte code
* Check whether current mock method is invoked from its associated test class
* should be invoked in mock method
*/
@ -39,6 +40,10 @@ public class MockAssociationUtil {
isAssociatedByMockWithAnnotation(testClassName, mockClassName);
}
/**
* Note: this method will be invoked in transformed byte code
* Invoke original method when mock class is not associated with current test case
*/
public static Object invokeOrigin(Class<?> originClass, String originMethod, Object... args) {
if (originMethod.equals(CONSTRUCTOR)) {
return PrivateAccessor.construct(originClass, args);