Я работаю над смешанным проектом JVM: классы в основном написаны на Java, а тесты — на Kotlin.
Итак, у меня есть Java
Код: Выделить всё
MyClassКод: Выделить всё
ParentClassКод: Выделить всё
@EntityКод: Выделить всё
ParentClassКод: Выделить всё
@Entity
@Setter
@Getter
public class MyClass extends ParentClass {
// some attributes
}
Код: Выделить всё
ParentClassКод: Выделить всё
@MappedSuperclass
@Getter
public class ParentClass {
private String value = "";
}
Since there are no
Код: Выделить всё
settersКод: Выделить всё
getValue()I've tried to use something like
Код: Выделить всё
mock.when(myMock.getValue()).thenReturn("my string")In kotlin tests I've tried multiple lines:
Код: Выделить всё
val myMock = mock(CALLS_REAL_METHODS)
`when`(myMock.value).thenReturn("")
// or using mockito kotlin
whenever(myMock.value).thenReturn("")
But it seems that not work's in that way.
Also I've tried this answer
Код: Выделить всё
val myMock = mock()
// And also
val myMock = org.mockito.kotlin.mock()
// And these two
`when`(myMock.value).thenReturn("")
whenever(myMock.value).thenReturn("")
Also tried:
Код: Выделить всё
val mock1: MyClass = mock(MyClass::class.java)
`when`(mock1.value).thenReturn("")
whenever(mock1.value).thenReturn("")
val mock2: MyClass = mock();
`when`(mock2.value).thenReturn("")
whenever(mock2.value).thenReturn("")
val mock3: MyClass = mock(CALLS_REAL_METHODS)
`when`(mock3.value).thenReturn("")
whenever(mock3.value).thenReturn("")
So, what I'm missing? Is any inter-op problem using Java and Kotlin? Is some
Код: Выделить всё
@EntityКод: Выделить всё
@MappedSuperclassDo I will need to use reflection?
Thanks in advance,
Источник: https://stackoverflow.com/questions/781 ... uper-class
Мобильная версия