mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-02-04 00:30:52 +08:00
remove unnecessary mock class reference in test class handler
This commit is contained in:
parent
20b346ed34
commit
55ccc385d5
@ -23,7 +23,6 @@ public class TestClassHandler extends BaseClassWithContextHandler {
|
|||||||
private static final String METHOD_CLEAN = "clean";
|
private static final String METHOD_CLEAN = "clean";
|
||||||
private static final String DESC_METHOD_CLEAN = "()V";
|
private static final String DESC_METHOD_CLEAN = "()V";
|
||||||
|
|
||||||
private final String mockClassName;
|
|
||||||
private int testCaseCount = 0;
|
private int testCaseCount = 0;
|
||||||
|
|
||||||
private final Framework[] frameworkClasses = new Framework[] {
|
private final Framework[] frameworkClasses = new Framework[] {
|
||||||
@ -33,10 +32,6 @@ public class TestClassHandler extends BaseClassWithContextHandler {
|
|||||||
new TestNgOnClassFramework()
|
new TestNgOnClassFramework()
|
||||||
};
|
};
|
||||||
|
|
||||||
public TestClassHandler(String mockClassName) {
|
|
||||||
this.mockClassName = mockClassName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle bytecode of test class
|
* Handle bytecode of test class
|
||||||
* @param cn original class node
|
* @param cn original class node
|
||||||
|
@ -66,7 +66,7 @@ public class TestableClassTransformer implements ClassFileTransformer {
|
|||||||
if (mockClass != null) {
|
if (mockClass != null) {
|
||||||
// it's a test class with testable enabled
|
// it's a test class with testable enabled
|
||||||
LogUtil.diagnose("Handling test class %s", className);
|
LogUtil.diagnose("Handling test class %s", className);
|
||||||
bytes = new TestClassHandler(mockClass).getBytes(bytes);
|
bytes = new TestClassHandler().getBytes(bytes);
|
||||||
dumpByte(className, bytes);
|
dumpByte(className, bytes);
|
||||||
} else {
|
} else {
|
||||||
mockClass = foundMockForSourceClass(className);
|
mockClass = foundMockForSourceClass(className);
|
||||||
|
@ -23,6 +23,7 @@ public class MockAssociationUtil {
|
|||||||
public static Map<String, Set<String>> mockToTests = UnnullableMap.of(new HashSet<String>());
|
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
|
* Check whether current mock method is invoked from its associated test class
|
||||||
* should be invoked in mock method
|
* should be invoked in mock method
|
||||||
*/
|
*/
|
||||||
@ -39,6 +40,10 @@ public class MockAssociationUtil {
|
|||||||
isAssociatedByMockWithAnnotation(testClassName, mockClassName);
|
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) {
|
public static Object invokeOrigin(Class<?> originClass, String originMethod, Object... args) {
|
||||||
if (originMethod.equals(CONSTRUCTOR)) {
|
if (originMethod.equals(CONSTRUCTOR)) {
|
||||||
return PrivateAccessor.construct(originClass, args);
|
return PrivateAccessor.construct(originClass, args);
|
||||||
|
Loading…
Reference in New Issue
Block a user