You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer the following questions for yourself before submitting an issue.
I am running the latest version
I checked the documentation and found no answer
I checked to make sure that this issue has not already been filed
Expected Behavior
The following Kotest-based test should pass:
class MockkMePlease(val foo: NonEmptySet<Int>) {
fun doStuff() {
throw Exception("This should be mocked")
}
}
class MockkInlineSpec : DescribeSpec({
describe("NonEmptySet in constructor") {
it("uses the mock") {
val mock = mockk<MockkMePlease>()
justRun { mock.doStuff() }
mock.doStuff()
verify { mock.doStuff() }
}
}
})
Current Behavior
All three references to doStuff - the blocks of justRun, verify as well as the call from the class under test - invoke the original implementation instead of the mockk-related behaviour.
Failure Information (for bugs)
Changing the constructor to use a regular Set instead of a NonEmptySet makes the implementation pass.
Steps to Reproduce
See above.
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
MockK version: 1.13.5
OS: Linux
Kotlin version: 1.9.0 (tested with 1.8.20 as well)
JDK version: openjdk version "17.0.7" 2023-04-18
JUnit version: 5.9.2
Type of test: unit test (KOtest)
Failure Logs
Please include any relevant log snippets or files here.
Stack trace
java.lang.Exception: This should be mocked
Minimal reproducible code (the gist of this issue)
// -----------------------[ GRADLE DEFINITIONS ] -----------------------
dependencies {
testImplementation("io.arrow-kt:arrow-core:1.2.0")
testImplementation("io.kotest:kotest-assertions-core:5.6.2")
testImplementation("io.kotest:kotest-framework-api-jvm:5.6.2")
}
// -----------------------[ YOUR CODE STARTS HERE ] -----------------------packageio.mockk.ghimportio.mockk.*importio.kotest.core.spec.style.DescribeSpecimportarrow.core.NonEmptySetclassMockkMePlease(valfoo:NonEmptySet<Int>) {
fundoStuff() {
throwException("This should be mocked")
}
}
classMockkInlineSpec : DescribeSpec({
describe("NonEmptySet in constructor") {
it("uses the mock") {
val mock = mockk<MockkMePlease>()
justRun { mock.doStuff() }
mock.doStuff()
verify { mock.doStuff() }
}
}
})
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
The text was updated successfully, but these errors were encountered:
Hi @milgner , I investigated this issue and found some hypothesis.
As NonEmptyList is inlined and has a generic parameter, the type information is lost in compile.
The problem is comes from both inlined class and a generic parameter.
// Constructor of NonEmptyList
@JvmInline
publicvalue classNonEmptySet<outA> private constructor(
privatevalelements:Set<A>
) : Set<A> by elements, NonEmptyCollection<A> {
// minimal reproducible codeclassTest : DescribeSpec({
describe("This will fail") {
val mock = mockk<DummyMockMePlease>()
justRun { mock.foo() }
mock.foo()
verify { mock.foo() }
}
describe("Success when only inline class") {
val mock = mockk<DummyMockMePlease2>()
justRun { mock.foo() }
mock.foo()
verify { mock.foo() }
}
describe("Success when only generics") {
val mock = mockk<DummyMockMePlease3>()
justRun { mock.foo() }
mock.foo()
verify { mock.foo() }
}
})
@JvmInline
value classDummyNonEmptySet<E>(valvalue:Set<E>)
classDummyMockMePlease(valarg0:DummyNonEmptySet<Int>) {
funfoo() {
throwException("This should be mocked.")
}
}
@JvmInline
value classDummyNonEmptySet2(valvalue:Set<Any>)
classDummyMockMePlease2(valarg0:DummyNonEmptySet2) {
funfoo() {
throwException("This should be mocked.")
}
}
classDummyNonEmptySet3 <E> (valvalue:Set<E>)
classDummyMockMePlease3(valarg0:DummyNonEmptySet3<Int>) {
funfoo() {
throwException("This should be mocked.")
}
}
However, I feel unsure of my hypothesis and do not know how to solve this issue...
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Expected Behavior
The following Kotest-based test should pass:
Current Behavior
All three references to
doStuff
- the blocks ofjustRun
,verify
as well as the call from the class under test - invoke the original implementation instead of the mockk-related behaviour.Failure Information (for bugs)
Changing the constructor to use a regular
Set
instead of aNonEmptySet
makes the implementation pass.Steps to Reproduce
See above.
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Failure Logs
Please include any relevant log snippets or files here.
Stack trace
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: