From 161345a6b7c2223a2c1653fb1e4ac7746c081c38 Mon Sep 17 00:00:00 2001
From: Pietro Scarampella
Date: Fri, 4 Jun 2021 11:44:55 +0200
Subject: [PATCH] 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...")
+ }
+ }
}