Skip to content

Commit 561795a

Browse files
authored
Merge pull request #1370 from VitalyVPinchuk/fix-1355
fix: handle fallback to default constructor parameters in constructed…
2 parents 9d1b6d6 + d2121ac commit 561795a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

modules/mockk/src/commonTest/kotlin/io/mockk/it/ConstructorMockTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ class ConstructorMockTest {
152152
}
153153
}
154154

155+
@Test
156+
fun `constructedWith() using default constructor params`() {
157+
mockkConstructor(MockCls::class)
158+
159+
every { constructedWith<MockCls>().op(1, 3) } returns 33
160+
161+
assertEquals(33, MockCls().op(1, 3))
162+
163+
verify {
164+
constructedWith<MockCls>().op(1, 3)
165+
}
166+
}
167+
155168
@Test
156169
fun unmockkAllconstructedWith() {
157170
mockkConstructor(MockCls::class)

modules/mockk/src/jvmMain/kotlin/io/mockk/impl/instantiation/JvmConstructorMockFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class JvmConstructorMockFactory(
116116

117117
private fun getConstructorMock(args: Array<Matcher<*>>?): ConstructorMock? {
118118
return synchronized(handlers) {
119-
if (args == null) {
119+
if (args.isNullOrEmpty()) {
120120
if (allHandler == null) {
121121
allHandler = ConstructorMock(cls, recordPrivateCalls)
122122
}

0 commit comments

Comments
 (0)