Skip to content

Commit 88b3420

Browse files
committed
Add notNull matcher tests in test-mokkery
1 parent c1ab1e8 commit 88b3420

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

test-mokkery/src/commonMain/kotlin/dev/mokkery/test/TestInterface.kt

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ interface TestInterface : BaseInterface {
44

55
var property: String
66

7+
fun callWithString(value: String?): Int
8+
79
fun callWithPrimitives(i: Int, j: Int = 1): Double
810

911
fun callWithComplex(list: List<String>): List<Int>

test-mokkery/src/commonTest/kotlin/dev/mokkery/test/ArgMatchersTest.kt

+12
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import dev.mokkery.matcher.lte
2424
import dev.mokkery.matcher.neq
2525
import dev.mokkery.matcher.neqRef
2626
import dev.mokkery.matcher.ofType
27+
import dev.mokkery.matcher.matchingBy
2728
import dev.mokkery.matcher.varargs.anyVarargs
2829
import dev.mokkery.matcher.varargs.varargsAll
2930
import dev.mokkery.matcher.varargs.varargsAny
31+
import dev.mokkery.matcher.nullable.notNull
3032
import dev.mokkery.mock
3133
import kotlin.test.Test
3234
import kotlin.test.assertContentEquals
@@ -347,5 +349,15 @@ class ArgMatchersTest {
347349
mock.callWithPrimitives(3)
348350
assertEquals(listOf(1, 3), called)
349351
}
352+
353+
@Test
354+
fun testNotNullMatcherAllowsUsingNotNullableMatchers() {
355+
every { mock.callWithString(any()) } returns 1
356+
every { mock.callWithString(notNull()) } returns 2
357+
every { mock.callWithString(notNull(matchingBy(CharSequence::isNotEmpty))) } returns 3
358+
assertEquals(1, mock.callWithString(null))
359+
assertEquals(2, mock.callWithString(""))
360+
assertEquals(3, mock.callWithString("Aaaaaaa"))
361+
}
350362
}
351363

test-mokkery/src/commonTest/kotlin/dev/mokkery/test/SpyTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class SpyTest {
9292
private object TestInterfaceImpl : TestInterface {
9393

9494
override var property: String = "1"
95+
override fun callWithString(value: String?): Int = 0
9596

9697
override fun callWithPrimitives(i: Int, j: Int): Double = i.toDouble()
9798

0 commit comments

Comments
 (0)