aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test/kotlin/test/VerifyTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/test/kotlin/test/VerifyTest.kt')
-rw-r--r--tests/src/test/kotlin/test/VerifyTest.kt96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/src/test/kotlin/test/VerifyTest.kt b/tests/src/test/kotlin/test/VerifyTest.kt
new file mode 100644
index 0000000..0a93832
--- /dev/null
+++ b/tests/src/test/kotlin/test/VerifyTest.kt
@@ -0,0 +1,96 @@
+package test
+
+import org.mockito.kotlin.any
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.verify
+import org.junit.Test
+import org.mockito.exceptions.verification.TooLittleActualInvocations
+import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent
+
+class VerifyTest : TestBase() {
+
+ @Test
+ fun verify0Calls() {
+ val iface = mock<TestInterface>()
+
+ verify(iface) {
+ 0 * { call(any()) }
+ }
+ }
+
+ @Test
+ fun verifyNCalls() {
+ val iface = mock<TestInterface>()
+
+ iface.call(42)
+ iface.call(42)
+
+ verify(iface) {
+ 2 * { call(42) }
+ }
+ }
+
+ @Test(expected = TooLittleActualInvocations::class)
+ fun verifyFailsWithWrongCount() {
+ val iface = mock<TestInterface>()
+
+ iface.call(0)
+
+ verify(iface) {
+ 2 * { call(0) }
+ }
+ }
+
+ @Test(expected = ArgumentsAreDifferent::class)
+ fun verifyFailsWithWrongArg() {
+ val iface = mock<TestInterface>()
+
+ iface.call(3)
+
+ verify(iface) {
+ 1 * { call(0) }
+ }
+ }
+
+ @Test
+ fun verifyDefaultArgs_firstParameter() {
+ /* Given */
+ val m = mock<TestInterface>()
+
+ /* When */
+ m.defaultArgs(a = 2)
+
+ /* Then */
+ verify(m).defaultArgs(2)
+ }
+
+ @Test
+ fun verifyDefaultArgs_secondParameter() {
+ /* Given */
+ val m = mock<TestInterface>()
+
+ /* When */
+ m.defaultArgs(b = 2)
+
+ /* Then */
+ verify(m).defaultArgs(b = 2)
+ }
+
+ @Test
+ fun verifyDefaultArgs_verifyDefaultValue() {
+ /* Given */
+ val m = mock<TestInterface>()
+
+ /* When */
+ m.defaultArgs(b = 2)
+
+ /* Then */
+ verify(m).defaultArgs(a = 3, b = 2)
+ }
+
+ interface TestInterface {
+ fun call(arg: Int)
+
+ fun defaultArgs(a: Int = 3, b: Int = 42)
+ }
+} \ No newline at end of file