Kotlin can automatically create getters for primary constructor parameters (that's great), and all these getters are final (not open) by default. I have a class (in Kotlin):
open class SongCategory(val id: Long,
val type: SongCategoryType,
val name: String? = null,
var displayName: String? = null,
var songs: List<Song>? = null) {
}
I wanted to use it in some Mockito test (in Java):
SongCategory songCategory = mock(SongCategory.class);
// the line below produces MissingMethodInvocationException
when(songCategory.getDisplayName()).thenReturn("Dupa");
This produces MissingMethodInvocationException because Mockito needs the mocked class to be open (not final) and the mocked method getDisplayName() just has to be open but it's not.
I can't make this getter open or create another overriding getter because it's conflicting with a final getter created automatically for a constructor.
I could move these all parameters to a secondary constructor and create all the properties and getters separately. However if I have to write the same boilerplate code as in Java, so what's the sense of using Kotlin then?
Is there some way to use Mockito with Kotlin-compiled getters?