move verify method to verifier class

This commit is contained in:
金戟 2020-11-17 14:06:59 +08:00
parent 7e77f77fa2
commit c68289920f
6 changed files with 17 additions and 20 deletions

View File

@ -5,8 +5,7 @@ import com.alibaba.testable.demo.model.BlackBox;
import org.junit.jupiter.api.Test;
import static com.alibaba.testable.core.matcher.InvokeMatcher.*;
import static com.alibaba.testable.core.tool.TestableTool.*;
import static com.alibaba.testable.core.matcher.InvokeVerifier.verify;
class DemoMatcherServiceTest {

View File

@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test;
import java.util.concurrent.Executors;
import static com.alibaba.testable.core.matcher.InvokeVerifier.verify;
import static com.alibaba.testable.core.tool.TestableTool.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

View File

@ -1,6 +1,7 @@
package com.alibaba.testable.demo.service
import com.alibaba.testable.core.annotation.TestableMock
import com.alibaba.testable.core.matcher.InvokeVerifier.verify
import com.alibaba.testable.core.tool.TestableTool.*
import com.alibaba.testable.demo.model.BlackBox
import com.alibaba.testable.demo.model.Box
@ -9,7 +10,6 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.util.concurrent.Executors
internal class DemoMockServiceTest {
@TestableMock(targetMethod = CONSTRUCTOR)

View File

@ -1,8 +1,8 @@
package com.alibaba.testable.demo.util
import org.junit.jupiter.api.Test
import com.alibaba.testable.core.annotation.TestableMock
import com.alibaba.testable.core.tool.TestableTool.verify
import com.alibaba.testable.core.matcher.InvokeVerifier.verify
import org.junit.jupiter.api.Test
import java.io.File
class PathUtilTest {

View File

@ -2,6 +2,7 @@ package com.alibaba.testable.core.matcher;
import com.alibaba.testable.core.error.VerifyFailedError;
import com.alibaba.testable.core.model.Verification;
import com.alibaba.testable.core.util.InvokeRecordUtil;
import com.alibaba.testable.core.util.TestableUtil;
import java.security.InvalidParameterException;
@ -15,10 +16,20 @@ public class InvokeVerifier {
private final List<Object[]> records;
private Verification lastVerification = null;
public InvokeVerifier(List<Object[]> records) {
private InvokeVerifier(List<Object[]> records) {
this.records = records;
}
/**
* Get counter to check whether specified mock method invoked
* @param mockMethodName name of a mock method
*/
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));
}
/**
* Expect mock method invoked with specified parameters
* @param args parameters to compare

View File

@ -1,9 +1,5 @@
package com.alibaba.testable.core.tool;
import com.alibaba.testable.core.matcher.InvokeVerifier;
import com.alibaba.testable.core.util.InvokeRecordUtil;
import com.alibaba.testable.core.util.TestableUtil;
/**
* @author flin
*/
@ -24,14 +20,4 @@ public class TestableTool {
*/
public static String SOURCE_METHOD;
/**
* Get counter to check whether specified mock method invoked
* @param mockMethodName name of a mock method
*/
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));
}
}