diff --git a/demo/java-demo/src/test/java/com/alibaba/testable/demo/service/DemoMatcherServiceTest.java b/demo/java-demo/src/test/java/com/alibaba/testable/demo/service/DemoMatcherServiceTest.java index 9c5a5e0..021732e 100644 --- a/demo/java-demo/src/test/java/com/alibaba/testable/demo/service/DemoMatcherServiceTest.java +++ b/demo/java-demo/src/test/java/com/alibaba/testable/demo/service/DemoMatcherServiceTest.java @@ -1,11 +1,13 @@ package com.alibaba.testable.demo.service; import com.alibaba.testable.core.annotation.TestableMock; +import com.alibaba.testable.core.error.VerifyFailedError; 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.matcher.InvokeVerifier.verify; +import static org.junit.jupiter.api.Assertions.fail; class DemoMatcherServiceTest { @@ -57,4 +59,21 @@ class DemoMatcherServiceTest { verify("methodWithArguments").withInOrder(isNull(), notNull()); } + @Test + void should_match_with_times() { + demo.callMethodWithNumberArguments(); + verify("methodWithArguments").with(anyNumber(), any()).times(3); + + demo.callMethodWithNumberArguments(); + boolean gotError = false; + try { + verify("methodWithArguments").with(anyNumber(), any()).times(4); + } catch (VerifyFailedError e) { + gotError = true; + } + if (!gotError) { + fail(); + } + } + } diff --git a/demo/kotlin-demo/src/test/kotlin/com/alibaba/testable/demo/service/DemoMatcherServiceTest.kt b/demo/kotlin-demo/src/test/kotlin/com/alibaba/testable/demo/service/DemoMatcherServiceTest.kt index 745a9e3..fae6c1b 100644 --- a/demo/kotlin-demo/src/test/kotlin/com/alibaba/testable/demo/service/DemoMatcherServiceTest.kt +++ b/demo/kotlin-demo/src/test/kotlin/com/alibaba/testable/demo/service/DemoMatcherServiceTest.kt @@ -1,9 +1,11 @@ package com.alibaba.testable.demo.service import com.alibaba.testable.core.annotation.TestableMock +import com.alibaba.testable.core.error.VerifyFailedError import com.alibaba.testable.core.matcher.InvokeMatcher import com.alibaba.testable.core.matcher.InvokeVerifier import com.alibaba.testable.demo.model.BlackBox +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test @@ -60,4 +62,21 @@ internal class DemoMatcherServiceTest { InvokeVerifier.verify("methodWithArguments").withInOrder(InvokeMatcher.nullable(BlackBox::class.java), InvokeMatcher.nullable(BlackBox::class.java)) InvokeVerifier.verify("methodWithArguments").withInOrder(InvokeMatcher.isNull(), InvokeMatcher.notNull()) } + + @Test + fun should_match_with_times() { + demo.callMethodWithNumberArguments() + InvokeVerifier.verify("methodWithArguments").with(InvokeMatcher.anyNumber(), InvokeMatcher.any()).times(3) + + demo.callMethodWithNumberArguments() + var gotError = false + try { + InvokeVerifier.verify("methodWithArguments").with(InvokeMatcher.anyNumber(), InvokeMatcher.any()).times(4) + } catch (e: VerifyFailedError) { + gotError = true + } + if (!gotError) { + Assertions.fail() + } + } }