mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-03-23 08:10:45 +08:00
add test for times method
This commit is contained in:
parent
15c7e9c48d
commit
5770a702cc
@ -1,11 +1,13 @@
|
|||||||
package com.alibaba.testable.demo.service;
|
package com.alibaba.testable.demo.service;
|
||||||
|
|
||||||
import com.alibaba.testable.core.annotation.TestableMock;
|
import com.alibaba.testable.core.annotation.TestableMock;
|
||||||
|
import com.alibaba.testable.core.error.VerifyFailedError;
|
||||||
import com.alibaba.testable.demo.model.BlackBox;
|
import com.alibaba.testable.demo.model.BlackBox;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static com.alibaba.testable.core.matcher.InvokeMatcher.*;
|
import static com.alibaba.testable.core.matcher.InvokeMatcher.*;
|
||||||
import static com.alibaba.testable.core.matcher.InvokeVerifier.verify;
|
import static com.alibaba.testable.core.matcher.InvokeVerifier.verify;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
class DemoMatcherServiceTest {
|
class DemoMatcherServiceTest {
|
||||||
|
|
||||||
@ -57,4 +59,21 @@ class DemoMatcherServiceTest {
|
|||||||
verify("methodWithArguments").withInOrder(isNull(), notNull());
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.alibaba.testable.demo.service
|
package com.alibaba.testable.demo.service
|
||||||
|
|
||||||
import com.alibaba.testable.core.annotation.TestableMock
|
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.InvokeMatcher
|
||||||
import com.alibaba.testable.core.matcher.InvokeVerifier
|
import com.alibaba.testable.core.matcher.InvokeVerifier
|
||||||
import com.alibaba.testable.demo.model.BlackBox
|
import com.alibaba.testable.demo.model.BlackBox
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
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.nullable(BlackBox::class.java), InvokeMatcher.nullable(BlackBox::class.java))
|
||||||
InvokeVerifier.verify("methodWithArguments").withInOrder(InvokeMatcher.isNull(), InvokeMatcher.notNull())
|
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>()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user