From 2fce79fa7abb89ac591a6fed3148fc57dbc0b2b0 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 10:47:07 +0200 Subject: [PATCH 01/15] feature[test]: refactoring issue #88 --- .../mockk/{gh/Issue88Test.kt => it/OfTypeTest.kt} | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) rename mockk/common/src/test/kotlin/io/mockk/{gh/Issue88Test.kt => it/OfTypeTest.kt} (80%) diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue88Test.kt b/mockk/common/src/test/kotlin/io/mockk/it/OfTypeTest.kt similarity index 80% rename from mockk/common/src/test/kotlin/io/mockk/gh/Issue88Test.kt rename to mockk/common/src/test/kotlin/io/mockk/it/OfTypeTest.kt index 19a050046..934c58fc5 100644 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue88Test.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/OfTypeTest.kt @@ -1,11 +1,18 @@ -package io.mockk.gh +package io.mockk.it -import io.mockk.* +import io.mockk.MockKException +import io.mockk.Runs +import io.mockk.every +import io.mockk.just +import io.mockk.mockk import kotlin.test.Test import kotlin.test.assertFailsWith +/** + * See issue 88 + */ @Suppress("UNUSED_PARAMETER") -class Issue88Test { +class OfTypeTest { open class B {} class C : B() {} class A { fun go(x: B) {} } @@ -48,4 +55,4 @@ class Issue88Test { mock.go(C()) } -} \ No newline at end of file +} From 5b09901231cb4931387ae139cbfa8c4fb11a57b7 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 10:47:21 +0200 Subject: [PATCH 02/15] feature[test]: refactoring issue #95 --- .../test/kotlin/io/mockk/gh/Issue95Test.kt | 41 ------------------- .../src/test/kotlin/io/mockk/it/SpyTestCls.kt | 36 +++++++++++++++- 2 files changed, 35 insertions(+), 42 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue95Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue95Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue95Test.kt deleted file mode 100644 index 545f4e20b..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue95Test.kt +++ /dev/null @@ -1,41 +0,0 @@ -package io.mockk.gh - -import io.mockk.every -import io.mockk.spyk -import kotlin.test.Test - -@Suppress("UNUSED_PARAMETER") -class Issue95Test { - class Foo { - - fun getInterface(list: List) = listOf(true) - - fun bar(t: String, list: List = getInterface(listOf(false))): String { - return "FOO" - } - - fun bar2(list: List = getInterface(listOf(false))): String { - return "FOO" - } - } - - @Test - fun testMock() { - val mocking = spyk(Foo()) - - every { - mocking.bar(any()) - } returns "FOO MOCKED" - - println(mocking.bar("hello")) - } - - @Test - fun test2() { - val mocking = spyk(Foo()) - - every { mocking.bar2() } returns "FOO MOCKED" - - println(mocking.bar2()) - } -} \ No newline at end of file diff --git a/mockk/common/src/test/kotlin/io/mockk/it/SpyTestCls.kt b/mockk/common/src/test/kotlin/io/mockk/it/SpyTestCls.kt index 5dfe8b5dd..3bc91b70c 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/SpyTestCls.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/SpyTestCls.kt @@ -79,6 +79,40 @@ class SpyTest { assertTrue(executed[3]) } + /** + * See issue #95 + */ + @Test + fun chainedCalls() { + val mocking = spyk(ChainedCallsCls()) + + every { mocking.bar(any()) } returns "FOO MOCKED" + + println(mocking.bar("hello")) + } + + @Test + fun chainedCalls2() { + val mocking = spyk(ChainedCallsCls()) + + every { mocking.bar2() } returns "FOO MOCKED" + + println(mocking.bar2()) + } + + class ChainedCallsCls { + + fun getInterface(list: List) = listOf(true) + + fun bar(t: String, list: List = getInterface(listOf(false))): String { + return "FOO" + } + + fun bar2(list: List = getInterface(listOf(false))): String { + return "FOO" + } + } + open class BaseTestCls(val someReference: String, val executed: Array) { open fun doSomething() { executed[0] = true @@ -103,4 +137,4 @@ class SpyTest { return 5 + a } } -} \ No newline at end of file +} From 8fa6144c5dfd4bbb9a920e87124350d9a14fb1b5 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 10:49:43 +0200 Subject: [PATCH 03/15] feature[test]: refactoring issue #103 --- .../test/kotlin/io/mockk/gh/Issue103Test.kt | 30 ------------------- .../io/mockk/it/PrivateFunctionsTest.kt | 25 ++++++++++++++++ 2 files changed, 25 insertions(+), 30 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue103Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue103Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue103Test.kt deleted file mode 100644 index 90967ef16..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue103Test.kt +++ /dev/null @@ -1,30 +0,0 @@ -package io.mockk.gh - -import io.mockk.every -import io.mockk.spyk -import io.mockk.verify -import kotlin.test.Test - -class Issue103Test { - class MyClass { - - fun myPublicMethod() { - myPrivateMethod() - } - - private fun myPrivateMethod() { - } - } - - @Test - fun getAdapter() { - val myClass = spyk(MyClass(), recordPrivateCalls = true) - every { myClass invokeNoArgs "myPrivateMethod" } returns Unit - - myClass.myPublicMethod() - - verify { - myClass invokeNoArgs "myPrivateMethod" - } - } -} \ No newline at end of file diff --git a/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt index c0bbcf44a..affe62bf3 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt @@ -65,6 +65,9 @@ class PrivateFunctionsTest { } } + /** + * See issue #103 + */ @Test fun privateCallsWithNullability() { val mock = spyk(recordPrivateCalls = true) @@ -75,6 +78,28 @@ class PrivateFunctionsTest { verify { mock["x"](any(), any(), any()) } } + @Test + fun mockPrivateMethodThatReturnsNothing() { + val myClass = spyk(PrivateNoReturnCls(), recordPrivateCalls = true) + every { myClass invokeNoArgs "myPrivateMethod" } returns Unit + + myClass.myPublicMethod() + + verify { + myClass invokeNoArgs "myPrivateMethod" + } + } + + class PrivateNoReturnCls { + + fun myPublicMethod() { + myPrivateMethod() + } + + private fun myPrivateMethod() { + } + } + class Abc { fun y() = x() From 7e3cf11caafd6d541b57c41cc1305fe4ed8efba3 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 10:55:41 +0200 Subject: [PATCH 04/15] feature[test]: refactoring issue #109 --- .../test/kotlin/io/mockk/gh/Issue109Test.kt | 31 ------------- .../src/test/kotlin/io/mockk/it/VerifyTest.kt | 45 ++++++++++++++++--- 2 files changed, 40 insertions(+), 36 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue109Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue109Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue109Test.kt deleted file mode 100644 index e6376944b..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue109Test.kt +++ /dev/null @@ -1,31 +0,0 @@ -package io.mockk.gh - -import io.mockk.* -import kotlin.test.Test - -class Issue109Test { - class Bar { - fun baz(foo: String) { - println(foo) - } - } - - class Foo { - override fun toString(): String { - return "foo" - } - } - - @Test - fun test() { - val foo = mockk() - val bar = mockk() - - every { bar.baz("$foo") } just runs - - bar.baz("$foo") - - verify(exactly = 1) { bar.baz("$foo") } - - } -} \ No newline at end of file diff --git a/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt index 7abefc72c..e1448d45c 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt @@ -1,13 +1,16 @@ package io.mockk.it -import io.mockk.* +import io.mockk.every +import io.mockk.just +import io.mockk.mockk +import io.mockk.runs +import io.mockk.verify +import io.mockk.verifyOrder +import io.mockk.verifySequence import kotlin.test.Test import kotlin.test.assertEquals class VerifyTest { - class MockCls { - fun op(a: Int) = a + 1 - } val mock = mockk() @@ -153,4 +156,36 @@ class VerifyTest { mock.op(7) } } -} \ No newline at end of file + + /** + * See issue #109 + */ + @Test + fun verifyWithToString() { + val foo = mockk() + val bar = mockk() + + every { bar.baz("$foo") } just runs + + bar.baz("$foo") + + verify(exactly = 1) { bar.baz("$foo") } + + } + + class Bar { + fun baz(foo: String) { + println(foo) + } + } + + class Foo { + override fun toString(): String { + return "foo" + } + } + + class MockCls { + fun op(a: Int) = a + 1 + } +} From 977a1511f3b6c4772fe9973b60c34998411881b7 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:02:15 +0200 Subject: [PATCH 05/15] feature[test]: refactoring issue #158 --- .../test/kotlin/io/mockk/gh/Issue158Test.kt | 22 ------- .../test/kotlin/io/mockk/it/MatcherTest.kt | 62 +++++++++++++------ .../test/kotlin/io/mockk/it/MockkClassTest.kt | 27 ++++++-- .../src/test/kotlin/io/mockk/it/OfTypeTest.kt | 58 ----------------- 4 files changed, 66 insertions(+), 103 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue158Test.kt delete mode 100644 mockk/common/src/test/kotlin/io/mockk/it/OfTypeTest.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue158Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue158Test.kt deleted file mode 100644 index 798bb1d1a..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue158Test.kt +++ /dev/null @@ -1,22 +0,0 @@ -package io.mockk.gh - -import io.mockk.every -import io.mockk.mockk -import kotlin.test.Test - -class Issue158Test { - class TestClass { - fun alwaysThrows() : Nothing { - throw RuntimeException("this can be any exception") - } - } - - private val targetClass = mockk() - - @Test - fun testNothingIsNotThrowingNPE() { - every { targetClass.alwaysThrows() } answers { - throw IllegalArgumentException("this is a test") - } - } -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt index daa913418..f78c98fb8 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt @@ -8,20 +8,6 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith class MatcherTest { - interface Wrapper - data class IntWrapper(val data: Int) : Wrapper - - class MockCls { - fun op(a: Int, b: Int): Int = a + b - - fun op(a: Wrapper?, b: Wrapper?): Int { - return if (a is IntWrapper && b is IntWrapper) { - a.data + b.data - } else { - 0 - } - } - } @MockK lateinit var mock: MockCls @@ -46,19 +32,19 @@ class MatcherTest { mock.op(IntWrapper(3), b) } } - + @Test fun nEqNRefEq() { val a = IntWrapper(3) val b = IntWrapper(4) - + every { mock.op(neq(a), nrefEq(b)) } returns 1 - + assertEquals(1, mock.op(b, a), "Answer should be one, as b != a and a != b, so both neq and nrefEq.") assertFailsWith("Should fail because a is eq to a, so neq fails") { mock.op(a, IntWrapper(4)) } assertFailsWith("Should fail because b is referencial equal tob, so nrefEq fails") { mock.op(b, b) } assertEquals(1, mock.op(b, IntWrapper(3))) - + verify { mock.op(b, IntWrapper(3)) } @@ -311,4 +297,42 @@ class MatcherTest { mock.op(IntWrapper(7), IntWrapper(8)) } } -} \ No newline at end of file + + /** + * See issue 88 + */ + @Test + fun ofTypeWithGenerics() { + val mock = mockk() + every { mock.go(ofType()) } just Runs + assertFailsWith(MockKException::class) { mock.go(B()) } + + every { mock.go(ofType()) } just Runs + mock.go(C()) + + every { mock.go(ofType()) } just Runs + mock.go(B()) + + every { mock.go(ofType()) } just Runs + mock.go(C()) + } + + interface Wrapper + data class IntWrapper(val data: Int) : Wrapper + + class MockCls { + fun op(a: Int, b: Int): Int = a + b + + fun op(a: Wrapper?, b: Wrapper?): Int { + return if (a is IntWrapper && b is IntWrapper) { + a.data + b.data + } else { + 0 + } + } + } + + open class B {} + class C : B() {} + class A { fun go(x: B) {} } +} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/MockkClassTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/MockkClassTest.kt index 263b1faa4..9de8cf6dc 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/MockkClassTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/MockkClassTest.kt @@ -1,6 +1,7 @@ package io.mockk.it import io.mockk.every +import io.mockk.mockk import io.mockk.mockkClass import io.mockk.verify import kotlin.test.Test @@ -8,10 +9,6 @@ import kotlin.test.assertEquals class MockkClassTest { - class MockCls { - fun op(a: Int, b: Int) = a + b - } - val mock = mockkClass(MockCls::class) /** @@ -25,4 +22,26 @@ class MockkClassTest { verify { mock.op(3, 4) } } + + private val targetClass = mockk() + + /** + * See issue #158 + */ + @Test + fun testNothingIsNotThrowingNPE() { + every { targetClass.alwaysThrows() } answers { + throw IllegalArgumentException("this is a test") + } + } + + class TestClass { + fun alwaysThrows() : Nothing { + throw RuntimeException("this can be any exception") + } + } + + class MockCls { + fun op(a: Int, b: Int) = a + b + } } diff --git a/mockk/common/src/test/kotlin/io/mockk/it/OfTypeTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/OfTypeTest.kt deleted file mode 100644 index 934c58fc5..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/it/OfTypeTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -package io.mockk.it - -import io.mockk.MockKException -import io.mockk.Runs -import io.mockk.every -import io.mockk.just -import io.mockk.mockk -import kotlin.test.Test -import kotlin.test.assertFailsWith - -/** - * See issue 88 - */ -@Suppress("UNUSED_PARAMETER") -class OfTypeTest { - open class B {} - class C : B() {} - class A { fun go(x: B) {} } - - @Test - fun test1() { - val mock = mockk() - - every { mock.go(ofType()) } just Runs - - assertFailsWith(MockKException::class) { - mock.go(B()) - } - } - - @Test - fun test2() { - val mock = mockk() - - every { mock.go(ofType()) } just Runs - - mock.go(C()) - } - - - @Test - fun test3() { - val mock = mockk() - - every { mock.go(ofType()) } just Runs - - mock.go(B()) - } - - @Test - fun test4() { - val mock = mockk() - - every { mock.go(ofType()) } just Runs - - mock.go(C()) - } -} From 67b5f17ad11e1cdedbec4c624e463b055f164828 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:06:53 +0200 Subject: [PATCH 06/15] feature[test]: refactoring issue #221 --- .../{gh/Issue221Test.kt => it/SetsTest.kt} | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) rename mockk/common/src/test/kotlin/io/mockk/{gh/Issue221Test.kt => it/SetsTest.kt} (86%) diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue221Test.kt b/mockk/common/src/test/kotlin/io/mockk/it/SetsTest.kt similarity index 86% rename from mockk/common/src/test/kotlin/io/mockk/gh/Issue221Test.kt rename to mockk/common/src/test/kotlin/io/mockk/it/SetsTest.kt index 7dbc6ee65..03c496bec 100644 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue221Test.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/SetsTest.kt @@ -1,4 +1,4 @@ -package io.mockk.gh +package io.mockk.it import io.mockk.every import io.mockk.isMockKMock @@ -7,20 +7,14 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue -class Issue221Test { - interface Foo { - fun getTasks(): Set - - fun getTask(): Task - } - - interface Task { - fun getSubTask(): Task - - fun doIt(): Int - } - +/** + * [Set]s related tests. + */ +class SetsTest { + /** + * See issue #221 + */ @Test fun returnsSetOfMocks() { val foo = mockk() @@ -36,4 +30,15 @@ class Issue221Test { assertTrue(isMockKMock(task2)) } -} \ No newline at end of file + interface Foo { + fun getTasks(): Set + + fun getTask(): Task + } + + interface Task { + fun getSubTask(): Task + + fun doIt(): Int + } +} From af7c9ea6b7b41b04bb723ae3e63d9bcd676b80e8 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:09:39 +0200 Subject: [PATCH 07/15] feature[test]: refactoring issue #312 --- .../ParametersWhitDefaultTest.kt} | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) rename mockk/common/src/test/kotlin/io/mockk/{gh/Issue312Test.kt => it/ParametersWhitDefaultTest.kt} (74%) diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue312Test.kt b/mockk/common/src/test/kotlin/io/mockk/it/ParametersWhitDefaultTest.kt similarity index 74% rename from mockk/common/src/test/kotlin/io/mockk/gh/Issue312Test.kt rename to mockk/common/src/test/kotlin/io/mockk/it/ParametersWhitDefaultTest.kt index 07437e5cd..6c7fe82cf 100644 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue312Test.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/ParametersWhitDefaultTest.kt @@ -1,19 +1,17 @@ -package io.mockk.gh +package io.mockk.it import io.mockk.every import io.mockk.mockk import kotlin.test.Test import kotlin.test.assertEquals -interface DefaultParam { - fun foo(param: String = "default"): String -} - -class Issue312Test { +class ParametersWhitDefaultTest { private val target = mockk() /** + * See issue #312. + * * Mocking a function with default parameter should match without specifying its * parameters. */ @@ -27,4 +25,8 @@ class Issue312Test { private companion object { const val STUB_STRING = "A string" } + + interface DefaultParam { + fun foo(param: String = "default"): String + } } From d43dfb46acbb9cffb385e571e61916de921c0592 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:12:28 +0200 Subject: [PATCH 08/15] feature[test]: removing Issue343Test.kt as it's already covered inside it.AdditionalAnswerTest.kt --- .../test/kotlin/io/mockk/gh/Issue343Test.kt | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue343Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue343Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue343Test.kt deleted file mode 100644 index b5b891081..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue343Test.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.mockk.gh - -import io.mockk.every -import io.mockk.mockk -import kotlin.test.Test -import kotlin.test.assertEquals - -class Issue343Test { - class MockCls { - fun op() = 0 - } - - val mock = mockk() - - @Test - fun andThenAnswer() { - // Setup - val firstAnswers = 1 - val secondAnswer = 2 - every { mock.op() } answers { firstAnswers } andThenAnswer { secondAnswer } - // Execute and Assert - assertEquals(firstAnswers, mock.op()) - assertEquals(secondAnswer, mock.op()) - } -} From fefb0c223e35210a1eaefad72c71d47544959037 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:17:21 +0200 Subject: [PATCH 09/15] feature[test]: refactoring issue #346 --- .../test/kotlin/io/mockk/gh/Issue346Test.kt | 21 --------------- .../io/mockk/it/PrivateFunctionsTest.kt | 27 ++++++++++++++++--- 2 files changed, 23 insertions(+), 25 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue346Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue346Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue346Test.kt deleted file mode 100644 index fb838c41f..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue346Test.kt +++ /dev/null @@ -1,21 +0,0 @@ -package io.mockk.gh - -import io.mockk.* -import kotlin.test.Test - -class Issue346Test { - class Cls { - private fun privateCall() = Unit - - fun pubCall() = privateCall() - } - - @Test - fun test() { - val mock = spyk(recordPrivateCalls = true) - - justRun { mock invokeNoArgs "privateCall" } - - mock.pubCall() - } -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt index affe62bf3..cb08bdce4 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/PrivateFunctionsTest.kt @@ -1,6 +1,13 @@ package io.mockk.it -import io.mockk.* +import io.mockk.Runs +import io.mockk.every +import io.mockk.just +import io.mockk.justRun +import io.mockk.mockkObject +import io.mockk.spyk +import io.mockk.verify +import io.mockk.verifySequence import kotlin.test.Test import kotlin.test.assertEquals @@ -65,9 +72,6 @@ class PrivateFunctionsTest { } } - /** - * See issue #103 - */ @Test fun privateCallsWithNullability() { val mock = spyk(recordPrivateCalls = true) @@ -78,6 +82,9 @@ class PrivateFunctionsTest { verify { mock["x"](any(), any(), any()) } } + /** + * See issue #103 + */ @Test fun mockPrivateMethodThatReturnsNothing() { val myClass = spyk(PrivateNoReturnCls(), recordPrivateCalls = true) @@ -90,6 +97,18 @@ class PrivateFunctionsTest { } } + /** + * See issue #346 + */ + @Test + fun justRunsWithPrivateMethod() { + val mock = spyk(recordPrivateCalls = true) + + justRun { mock invokeNoArgs "myPrivateMethod" } + + mock.myPublicMethod() + } + class PrivateNoReturnCls { fun myPublicMethod() { From 6a03bb30f25df51c54384ad8f97b9a9b3f3cd27f Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:23:45 +0200 Subject: [PATCH 10/15] feature[test]: refactoring issue #352 --- .../test/kotlin/io/mockk/gh/Issue352Test.kt | 86 --------------- .../test/kotlin/io/mockk/it/CapturingTest.kt | 104 ++++++++++++++++-- 2 files changed, 94 insertions(+), 96 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue352Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue352Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue352Test.kt deleted file mode 100644 index 99f85d8ab..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue352Test.kt +++ /dev/null @@ -1,86 +0,0 @@ -package io.mockk.gh - -import io.mockk.MockKException -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import io.mockk.verify -import io.mockk.verifyOrder -import kotlin.test.BeforeTest -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith - -class Issue352Test { - - open class MockedSubject { - open fun doSomething(id: String?, data: Any?): String { - throw IllegalStateException("Not mocked :(") - } - } - - private val mock = mockk() - - @BeforeTest - fun setup() { - every { mock.doSomething("1", "data1") } returns "result1" - every { mock.doSomething("2", "data2") } returns "result2" - } - - @Test - fun itThrowsAMockkExceptionWhenVerifyingTheSameFunctionTwiceWithSlots() { - mock.doSomething("1", "data1") - mock.doSomething("2", "data2") - - val dataSlotId1 = slot() - val dataSlotId2 = slot() - - assertFailsWith { - verify { - mock.doSomething("1", capture(dataSlotId1)) - mock.doSomething("2", capture(dataSlotId2)) - } - } - } - - @Test - fun itDoesNotThrowAMockkExceptionWhenThereAreMultipleTestsVerifyingWithSlots() { - mock.doSomething("1", "data1") - - val slot = slot() - verify { - mock.doSomething("1", capture(slot)) - } - - assertEquals("data1", slot.captured) - } - - @Test - fun anotherTestToTestTheCoexistenceOfTestsWithSlots() { - mock.doSomething("1", "data1") - - val slot = slot() - verify { - mock.doSomething("1", capture(slot)) - } - - assertEquals("data1", slot.captured) - } - - @Test - fun itAllowsMultipleCapturingsOfTheSameFunctionUsingAMutableList() { - mock.doSomething("1", "data1") - mock.doSomething("2", "data2") - - val slotList = mutableListOf() - - verify { - mock.doSomething("1", capture(slotList)) - mock.doSomething("2", capture(slotList)) - } - - assertEquals("data1", slotList[0]) - assertEquals("data2", slotList[1]) - } - -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt index 5a6b46ebf..a7f4f8003 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt @@ -1,21 +1,19 @@ package io.mockk.it import io.mockk.* +import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class CapturingTest { - class Cls { - var value = 0 - } - - class MockCls { - fun op(a: Int, b: Int, c: Cls) = a + b + c.value - } + private val mock = mockk() - class CoMockCls { - suspend fun op(a: Int, b: Int, c: Cls) = a + b + c.value + @BeforeTest + fun setup() { + every { mock.doSomething("1", "data1") } returns "result1" + every { mock.doSomething("2", "data2") } returns "result2" } @Test @@ -73,4 +71,90 @@ class CapturingTest { coVerify { mock.op(1, 2, any()) } } -} \ No newline at end of file + + /** + * See issue #352. + */ + @Test + fun itThrowsAMockkExceptionWhenVerifyingTheSameFunctionTwiceWithSlots() { + mock.doSomething("1", "data1") + mock.doSomething("2", "data2") + + val dataSlotId1 = slot() + val dataSlotId2 = slot() + + assertFailsWith { + verify { + mock.doSomething("1", capture(dataSlotId1)) + mock.doSomething("2", capture(dataSlotId2)) + } + } + } + + /** + * See issue #352. + */ + @Test + fun itDoesNotThrowAMockkExceptionWhenThereAreMultipleTestsVerifyingWithSlots() { + mock.doSomething("1", "data1") + + val slot = slot() + verify { + mock.doSomething("1", capture(slot)) + } + + assertEquals("data1", slot.captured) + } + + /** + * See issue #352. + */ + @Test + fun anotherTestToTestTheCoexistenceOfTestsWithSlots() { + mock.doSomething("1", "data1") + + val slot = slot() + verify { + mock.doSomething("1", capture(slot)) + } + + assertEquals("data1", slot.captured) + } + + /** + * See issue #352. + */ + @Test + fun itAllowsMultipleCapturingsOfTheSameFunctionUsingAMutableList() { + mock.doSomething("1", "data1") + mock.doSomething("2", "data2") + + val slotList = mutableListOf() + + verify { + mock.doSomething("1", capture(slotList)) + mock.doSomething("2", capture(slotList)) + } + + assertEquals("data1", slotList[0]) + assertEquals("data2", slotList[1]) + } + + class Cls { + var value = 0 + } + + class MockCls { + fun op(a: Int, b: Int, c: Cls) = a + b + c.value + } + + class CoMockCls { + suspend fun op(a: Int, b: Int, c: Cls) = a + b + c.value + } + + open class MockedSubject { + open fun doSomething(id: String?, data: Any?): String { + throw IllegalStateException("Not mocked :(") + } + } +} From d7e52457ff991ee2432421448cdb29619050e69f Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:26:12 +0200 Subject: [PATCH 11/15] feature[test]: refactoring issue #353 --- .../test/kotlin/io/mockk/gh/Issue353Test.kt | 32 ------------------- .../test/kotlin/io/mockk/it/CapturingTest.kt | 24 ++++++++++++++ 2 files changed, 24 insertions(+), 32 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue353Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue353Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue353Test.kt deleted file mode 100644 index 872e4cd66..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue353Test.kt +++ /dev/null @@ -1,32 +0,0 @@ -package io.mockk.gh - -import io.mockk.Runs -import io.mockk.every -import io.mockk.just -import io.mockk.mockk -import kotlin.test.Test -import kotlin.test.assertEquals - -class Issue353Test { - - @Test - fun testNullableCapture() { - class Mock { - fun call(unused: String?) { - println(unused) - } - } - - val list = mutableListOf() - val test: Mock = mockk { - every { call(captureNullable(list)) } just Runs - } - - val args = listOf("One", "Two", "Three", null) - for (arg in args) { - test.call(arg) - } - - assertEquals(args, list) - } -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt index a7f4f8003..dd9f310cb 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/CapturingTest.kt @@ -140,6 +140,30 @@ class CapturingTest { assertEquals("data2", slotList[1]) } + /** + * See issue #353. + */ + @Test + fun testNullableCapture() { + val list = mutableListOf() + val test: MockNullableCls = mockk { + every { call(captureNullable(list)) } just Runs + } + + val args = listOf("One", "Two", "Three", null) + for (arg in args) { + test.call(arg) + } + + assertEquals(args, list) + } + + class MockNullableCls { + fun call(unused: String?) { + println(unused) + } + } + class Cls { var value = 0 } From e46e2b6480d90c3da18425119078f6c129029660 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:32:35 +0200 Subject: [PATCH 12/15] feature[test]: refactoring issue #389 --- .../test/kotlin/io/mockk/gh/Issue389Test.kt | 42 ------------------- .../src/test/kotlin/io/mockk/it/VerifyTest.kt | 37 ++++++++++++++++ 2 files changed, 37 insertions(+), 42 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue389Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue389Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue389Test.kt deleted file mode 100644 index 7f458e084..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue389Test.kt +++ /dev/null @@ -1,42 +0,0 @@ -package io.mockk.gh - -import io.mockk.mockk -import io.mockk.verifyAll -import kotlin.test.Ignore -import kotlin.test.Test -import kotlin.test.assertEquals - -class Tweet(val id: Int, val text: String) - -interface TweetRepository { - - fun persist(tweet: Tweet) - -} - -class Issue389Test { - - @Test - @Ignore - // Temporarily ignored because it suddenly started failing only on Github actions - internal fun verifyMultiplePersists() { - val repositoryMock = mockk(relaxed = true) - - repositoryMock.persist(Tweet(1, "first tweet")) - repositoryMock.persist(Tweet(2, "second tweet")) - - - verifyAll { - repositoryMock.persist( - withArg { - assertEquals(it.id, 1) - assertEquals(it.text, "first tweet") - }) - repositoryMock.persist( - withArg { - assertEquals(it.id,2) - assertEquals(it.text, "second tweet") - }) - } - } -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt index e1448d45c..c546f4c00 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/VerifyTest.kt @@ -5,8 +5,10 @@ import io.mockk.just import io.mockk.mockk import io.mockk.runs import io.mockk.verify +import io.mockk.verifyAll import io.mockk.verifyOrder import io.mockk.verifySequence +import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals @@ -173,6 +175,33 @@ class VerifyTest { } + /** + * See issue #389. + */ + @Test + @Ignore + // Temporarily ignored because it suddenly started failing only on Github actions + internal fun verifyUsingVerifyAll() { + val repositoryMock = mockk(relaxed = true) + + repositoryMock.persist(Tweet(1, "first tweet")) + repositoryMock.persist(Tweet(2, "second tweet")) + + + verifyAll { + repositoryMock.persist( + withArg { + assertEquals(it.id, 1) + assertEquals(it.text, "first tweet") + }) + repositoryMock.persist( + withArg { + assertEquals(it.id, 2) + assertEquals(it.text, "second tweet") + }) + } + } + class Bar { fun baz(foo: String) { println(foo) @@ -188,4 +217,12 @@ class VerifyTest { class MockCls { fun op(a: Int) = a + 1 } + + class Tweet(val id: Int, val text: String) + + interface TweetRepository { + + fun persist(tweet: Tweet) + + } } From 4b14b967a31cf8b81a9f36673cd15bb84bcd2ebd Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:37:07 +0200 Subject: [PATCH 13/15] feature[test]: refactoring issue #507 --- .../test/kotlin/io/mockk/gh/Issue507Test.kt | 44 ------------------- .../it/VerifyAtLeastAtMostExactlyTest.kt | 43 +++++++++++++++++- 2 files changed, 42 insertions(+), 45 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue507Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue507Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue507Test.kt deleted file mode 100644 index f5f4e99f2..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue507Test.kt +++ /dev/null @@ -1,44 +0,0 @@ -package io.mockk.gh - -import io.mockk.mockk -import io.mockk.verifyOrder -import kotlin.test.Test - -interface Tracker { - fun track(song: String, action: String, param: String, moreParam: Map) -} - -class Player(private val tracker: Tracker) { - fun goCrazy() { - tracker.track("song 2", "play", "param", mapOf(Pair("key", "value"))) - tracker.track("song 2", "pause", "param", mapOf(Pair("key", "value"))) - tracker.track("song 2", "play", "param", mapOf(Pair("key", "value"))) - tracker.track("song 2", "pause", "param", mapOf(Pair("key", "value"))) - tracker.track("song 2", "play", "param", mapOf(Pair("key", "value"))) - } -} - - -class Issue507Test { - - /** - * A regression occurred in version 1.10.2 causing verify order to use - * eq() instead of any() matcher. - * This test exist to avoid this kind of regression in the future. - */ - @Test - fun checkAgainstVerifyOrder() { - val tracker = mockk(relaxUnitFun = true) - val player = Player(tracker) - - player.goCrazy() - - verifyOrder { - tracker.track(any(), "play", "param", any()) - tracker.track(any(), "pause", "param", any()) - tracker.track(any(), "play", "param", any()) - tracker.track(any(), "pause", "param", any()) - tracker.track(any(), "play", "param", any()) - } - } -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt index 057bf1458..e5b74f858 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt @@ -1,6 +1,11 @@ package io.mockk.it -import io.mockk.* +import io.mockk.Called +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import io.mockk.verifyOrder +import io.mockk.verifySequence import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -145,6 +150,29 @@ class VerifyAtLeastAtMostExactlyTest { } } + /** + * See issue #507 + * + * A regression occurred in version 1.10.2 causing verify order to use + * eq() instead of any() matcher. + * This test exist to avoid this kind of regression in the future. + */ + @Test + fun orderWithAny() { + val tracker = mockk(relaxUnitFun = true) + val player = Player(tracker) + + player.goCrazy() + + verifyOrder { + tracker.track(any(), "play", "param", any()) + tracker.track(any(), "pause", "param", any()) + tracker.track(any(), "play", "param", any()) + tracker.track(any(), "pause", "param", any()) + tracker.track(any(), "play", "param", any()) + } + } + @Test fun sequence() { doCalls() @@ -188,4 +216,17 @@ class VerifyAtLeastAtMostExactlyTest { assertEquals(3, mock.op2(2, 1)) } + interface Tracker { + fun track(song: String, action: String, param: String, moreParam: Map) + } + + class Player(private val tracker: Tracker) { + fun goCrazy() { + tracker.track("song 2", "play", "param", mapOf(Pair("key", "value"))) + tracker.track("song 2", "pause", "param", mapOf(Pair("key", "value"))) + tracker.track("song 2", "play", "param", mapOf(Pair("key", "value"))) + tracker.track("song 2", "pause", "param", mapOf(Pair("key", "value"))) + tracker.track("song 2", "play", "param", mapOf(Pair("key", "value"))) + } + } } From 161345a6b7c2223a2c1653fb1e4ac7746c081c38 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:44:55 +0200 Subject: [PATCH 14/15] feature[test]: refactoring issue #510 --- .../test/kotlin/io/mockk/gh/Issue510Test.kt | 56 ------------------ .../test/kotlin/io/mockk/it/MatcherTest.kt | 58 ++++++++++++++++++- 2 files changed, 56 insertions(+), 58 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue510Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue510Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue510Test.kt deleted file mode 100644 index cb6950122..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue510Test.kt +++ /dev/null @@ -1,56 +0,0 @@ -package io.mockk.gh - -import io.mockk.clearAllMocks -import io.mockk.every -import io.mockk.mockk -import kotlin.test.BeforeTest -import kotlin.test.Test - -data class Product(val name: String, val price: Int) -data class Order(val name: String) - -class ShopService { - - fun buyProducts(products: List) { - println("You bought $products...") - } - - fun addProductAndOrders(products: List, orders: List) { - println("Add $products and $orders...") - } -} - -class TestMockk { - - private val shopService = mockk() - - @BeforeTest - internal fun setUp() { - clearAllMocks() - } - - @Test - internal fun shouldMatchListOfArguments() { // Passes - - every { - shopService.buyProducts(any()) - } returns Unit - val products = listOf(Product("raspberry", 2), Product("banana", 212)) - - shopService.buyProducts(products) - - } - - @Test - internal fun shouldMatchWithTwoArgumentsOfTypeList() { // Throws MockkException - - every { - shopService.addProductAndOrders(products = any(), orders = any()) - } returns Unit - - val products = listOf(Product("raspberry", 2), Product("banana", 1)) - val orders = listOf(Order("raspber"), Order("banana")) - - shopService.addProductAndOrders(products, orders) // Throws MockkException - } -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt index f78c98fb8..15b42b8e5 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/MatcherTest.kt @@ -1,7 +1,14 @@ package io.mockk.it -import io.mockk.* +import io.mockk.MockKAnnotations +import io.mockk.MockKException +import io.mockk.Runs +import io.mockk.every import io.mockk.impl.annotations.MockK +import io.mockk.just +import io.mockk.mockk +import io.mockk.slot +import io.mockk.verify import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals @@ -12,6 +19,9 @@ class MatcherTest { @MockK lateinit var mock: MockCls + @MockK + private lateinit var shopService: ShopService + @BeforeTest fun init() { MockKAnnotations.init(this) @@ -317,6 +327,34 @@ class MatcherTest { mock.go(C()) } + /** + * See issue #510 + */ + @Test + fun anyWithLists() { + every { + shopService.buyProducts(any()) + } returns Unit + val products = listOf(Product("raspberry", 2), Product("banana", 212)) + + shopService.buyProducts(products) + } + + /** + * See issue #510 + */ + @Test + fun anyWithTwoListArgument() { + every { + shopService.addProductAndOrders(products = any(), orders = any()) + } returns Unit + + val products = listOf(Product("raspberry", 2), Product("banana", 1)) + val orders = listOf(Order("raspber"), Order("banana")) + + shopService.addProductAndOrders(products, orders) // Throws MockkException + } + interface Wrapper data class IntWrapper(val data: Int) : Wrapper @@ -334,5 +372,21 @@ class MatcherTest { open class B {} class C : B() {} - class A { fun go(x: B) {} } + class A { + fun go(x: B) {} + } + + data class Product(val name: String, val price: Int) + data class Order(val name: String) + + class ShopService { + + fun buyProducts(products: List) { + println("You bought $products...") + } + + fun addProductAndOrders(products: List, orders: List) { + println("Add $products and $orders...") + } + } } From f63b4913e65d8008b498fd0e41fe93d37dc540d5 Mon Sep 17 00:00:00 2001 From: Pietro Scarampella Date: Fri, 4 Jun 2021 11:46:51 +0200 Subject: [PATCH 15/15] feature[test]: refactoring issue #614 --- .../test/kotlin/io/mockk/gh/Issue614Test.kt | 20 ------------------- .../it/VerifyAtLeastAtMostExactlyTest.kt | 19 ++++++++++++++---- 2 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 mockk/common/src/test/kotlin/io/mockk/gh/Issue614Test.kt diff --git a/mockk/common/src/test/kotlin/io/mockk/gh/Issue614Test.kt b/mockk/common/src/test/kotlin/io/mockk/gh/Issue614Test.kt deleted file mode 100644 index 48c93fed6..000000000 --- a/mockk/common/src/test/kotlin/io/mockk/gh/Issue614Test.kt +++ /dev/null @@ -1,20 +0,0 @@ -package io.mockk.gh - -import io.mockk.mockk -import io.mockk.verifyOrder -import kotlin.test.Test -import kotlin.test.assertFailsWith - -class Issue614Test { - - @Test - fun verifyOrderThrowAssertionErrorIfNoCallHasBeenMade() { - val mock: Something = mockk(relaxed = true, relaxUnitFun = true) - - assertFailsWith { verifyOrder { mock.doSomething() } } - } - - open class Something { - fun doSomething() {} - } -} diff --git a/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt b/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt index e5b74f858..a7ebd348d 100644 --- a/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt +++ b/mockk/common/src/test/kotlin/io/mockk/it/VerifyAtLeastAtMostExactlyTest.kt @@ -11,10 +11,6 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith class VerifyAtLeastAtMostExactlyTest { - class MockCls { - fun op(a: Int) = a + 1 - fun op2(a: Int, b: Int) = a + b - } val mock = mockk() @@ -173,6 +169,16 @@ class VerifyAtLeastAtMostExactlyTest { } } + /** + * See issue #614 + */ + @Test + fun verifyOrderThrowAssertionErrorIfNoCallHasBeenMade() { + val mock: MockCls = mockk(relaxed = true, relaxUnitFun = true) + + assertFailsWith { verifyOrder { mock.op(any()) } } + } + @Test fun sequence() { doCalls() @@ -216,6 +222,11 @@ class VerifyAtLeastAtMostExactlyTest { assertEquals(3, mock.op2(2, 1)) } + class MockCls { + fun op(a: Int) = a + 1 + fun op2(a: Int, b: Int) = a + b + } + interface Tracker { fun track(song: String, action: String, param: String, moreParam: Map) }