mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-10 20:30:11 +08:00
avoid test case naming conflict between classes
This commit is contained in:
parent
b74b21cae6
commit
65807eece7
@ -28,7 +28,8 @@ public class InvokeVerifier {
|
||||
public static InvokeVerifier verify(String mockMethodName) {
|
||||
String testClass = Thread.currentThread().getStackTrace()[InvokeRecordUtil.INDEX_OF_TEST_CLASS].getClassName();
|
||||
String testCaseName = TestableUtil.currentTestCaseName(testClass);
|
||||
return new InvokeVerifier(InvokeRecordUtil.getInvokeRecord(mockMethodName, testCaseName));
|
||||
String recordIdentify = InvokeRecordUtil.getInvokeIdentify(mockMethodName, testClass, testCaseName);
|
||||
return new InvokeVerifier(InvokeRecordUtil.getInvokeRecord(recordIdentify));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,27 +31,36 @@ public class InvokeRecordUtil {
|
||||
String mockMethodName = mockMethodTraceElement.getMethodName();
|
||||
String testClass = mockMethodTraceElement.getClassName();
|
||||
String testCaseName = TestableUtil.currentTestCaseName(testClass);
|
||||
String key = testCaseName + JOINER + mockMethodName;
|
||||
List<Object[]> records = getInvokeRecord(mockMethodName, testCaseName);
|
||||
String identify = getInvokeIdentify(mockMethodName, testClass, testCaseName);
|
||||
List<Object[]> records = getInvokeRecord(identify);
|
||||
if (isConstructor) {
|
||||
records.add(args);
|
||||
LogUtil.verbose("Mock constructor invoked \"%s\"", key);
|
||||
LogUtil.verbose("Mock constructor invoked \"%s\"", identify);
|
||||
} else {
|
||||
records.add(slice(args, 1));
|
||||
LogUtil.verbose("Mock method invoked \"%s\"", key);
|
||||
LogUtil.verbose("Mock method invoked \"%s\"", identify);
|
||||
}
|
||||
INVOKE_RECORDS.put(key, records);
|
||||
INVOKE_RECORDS.put(identify, records);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get identify key for mock invocation record
|
||||
* @param mockMethodName mock method name
|
||||
* @param testClass test class name
|
||||
* @param testCaseName test case name
|
||||
* @return identify key
|
||||
*/
|
||||
public static String getInvokeIdentify(String mockMethodName, String testClass, String testCaseName) {
|
||||
return testClass + JOINER + testCaseName + JOINER + mockMethodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mock method invoke count
|
||||
* @param mockMethodName mock method name
|
||||
* @param testCaseName test case name
|
||||
* @param identify key of invocation record
|
||||
* @return parameters used when specified method invoked in specified test case
|
||||
*/
|
||||
public static List<Object[]> getInvokeRecord(String mockMethodName, String testCaseName) {
|
||||
String key = testCaseName + JOINER + mockMethodName;
|
||||
List<Object[]> records = INVOKE_RECORDS.get(key);
|
||||
public static List<Object[]> getInvokeRecord(String identify) {
|
||||
List<Object[]> records = INVOKE_RECORDS.get(identify);
|
||||
return (records == null) ? new LinkedList<Object[]>() : records;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user