Skip to content

Commit

Permalink
feature[test]: refactoring issue mockk#510
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Scarampella committed Jun 4, 2021
1 parent 4b14b96 commit 161345a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 58 deletions.
56 changes: 0 additions & 56 deletions mockk/common/src/test/kotlin/io/mockk/gh/Issue510Test.kt

This file was deleted.

58 changes: 56 additions & 2 deletions 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
Expand All @@ -12,6 +19,9 @@ class MatcherTest {
@MockK
lateinit var mock: MockCls

@MockK
private lateinit var shopService: ShopService

@BeforeTest
fun init() {
MockKAnnotations.init(this)
Expand Down Expand Up @@ -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

Expand All @@ -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<Product>) {
println("You bought $products...")
}

fun addProductAndOrders(products: List<Product>, orders: List<Order>) {
println("Add $products and $orders...")
}
}
}

0 comments on commit 161345a

Please sign in to comment.