add test for times method

This commit is contained in:
金戟 2020-11-18 10:29:44 +08:00
parent 15c7e9c48d
commit 5770a702cc
2 changed files with 38 additions and 0 deletions

View File

@ -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();
}
}
}

View File

@ -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<Any>()
}
}
}