mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-10 20:30:11 +08:00
reduce log reset frequency
This commit is contained in:
parent
65807eece7
commit
bd0ec5f4b7
@ -40,22 +40,24 @@ public class TestableClassTransformer implements ClassFileTransformer {
|
|||||||
// Ignore system class and reloaded class
|
// Ignore system class and reloaded class
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
byte[] bytes = null;
|
||||||
try {
|
try {
|
||||||
if (shouldTransformAsSourceClass(className)) {
|
if (shouldTransformAsSourceClass(className)) {
|
||||||
// it's a source class with testable enabled
|
// it's a source class with testable enabled
|
||||||
LogUtil.diagnose("Handling source class %s", className);
|
LogUtil.diagnose("Handling source class %s", className);
|
||||||
List<MethodInfo> injectMethods = getTestableMockMethods(ClassUtil.getTestClassName(className));
|
List<MethodInfo> injectMethods = getTestableMockMethods(ClassUtil.getTestClassName(className));
|
||||||
return new SourceClassHandler(injectMethods).getBytes(classFileBuffer);
|
bytes = new SourceClassHandler(injectMethods).getBytes(classFileBuffer);
|
||||||
|
resetMockContext();
|
||||||
} else if (shouldTransformAsTestClass(className)) {
|
} else if (shouldTransformAsTestClass(className)) {
|
||||||
// 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);
|
||||||
return new TestClassHandler().getBytes(classFileBuffer);
|
bytes = new TestClassHandler().getBytes(classFileBuffer);
|
||||||
|
resetMockContext();
|
||||||
}
|
}
|
||||||
LogUtil.resetLogLevel();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
LogUtil.warn("Failed to transform class " + className);
|
||||||
}
|
}
|
||||||
return null;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldTransformAsSourceClass(String className) {
|
private boolean shouldTransformAsSourceClass(String className) {
|
||||||
@ -155,6 +157,10 @@ public class TestableClassTransformer implements ClassFileTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetMockContext() {
|
||||||
|
LogUtil.resetLogLevel();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split desc to "first parameter" and "desc of rest parameters"
|
* Split desc to "first parameter" and "desc of rest parameters"
|
||||||
* @param desc method desc
|
* @param desc method desc
|
||||||
|
Loading…
Reference in New Issue
Block a user