-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Problem
When following the guide to mock a class, if the target class contains a field matching one of the ones found within MokkeryInterceptorScope you will receive a compile time error as the compiler tries to generate getters / setters for the 2 fields with matching signatures.
The interceptor
and interceptedTypes
are unlikely to cause this issue however the id
field is a very common field name, especially for API or database models.
Repro Steps
Take the given class
class BrokenMock(
val id: String,
val someOtherField: String
)
and attempt to mock it
val testMock = mock<BrokenMock> { ... }
The following errors will appear
JVM
java.lang.ClassFormatError: Duplicate method name "getId" with signature "()Ljava.lang.String;" in class file <Class>
iOS
java.lang.IllegalStateException: IrPropertySymbolImpl is already bound. Signature: /<Class>.id|{}id[0]. Owner: PROPERTY name:id visibility:public modality:FINAL [val]
Proposed Solution
Refactor the id
field within MokkeryInterceptorScope to something more specific to this project that is highly unlikely (and less problematic) to be used in a production app. Eg. mokkeryId
The above solution could also be applied to interceptor
and interceptorTypes
(mokkeyInterceptor
, mokkeyInterceptorTypes
), however this is less critical