Skip to content

Commit ecb3588

Browse files
committed
Update test to work with Kotlin override properties.
1 parent 2bca4c9 commit ecb3588

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt

+15-6
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,38 @@
1515
*/
1616
package org.springframework.data.mongodb.core
1717

18-
import com.mongodb.MongoClient
18+
import com.mongodb.client.MongoClients
1919
import org.junit.Test
20+
import org.springframework.data.mongodb.core.mapping.Field
2021
import org.springframework.data.mongodb.repository.MongoRepository
2122
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory
2223
import org.springframework.data.mongodb.test.util.Assertions.assertThat
2324

24-
open class SuperType(open val field: Int)
25+
open class SuperType(open var field: Int)
2526

26-
class SubType(val id: String, override var field: Int = 1) : SuperType(field)
27+
class SubType(val id: String, @Field("foo") override var field: Int = 1) :
28+
SuperType(field) {
29+
30+
fun setFields(v: Int) {
31+
field = v
32+
super.field = v
33+
}
34+
}
2735

2836
interface MyRepository : MongoRepository<SubType, String>
2937

3038
class `KotlinOverridePropertyTests` {
3139

32-
val template = MongoTemplate(MongoClient(), "kotlin-tests")
40+
val template = MongoTemplate(MongoClients.create(), "kotlin-tests")
3341

3442
@Test // DATAMONGO-2250
3543
fun `Ambiguous field mapping for override val field`() {
3644

37-
val repository = MongoRepositoryFactory(template).getRepository(MyRepository::class.java)
45+
val repository =
46+
MongoRepositoryFactory(template).getRepository(MyRepository::class.java)
3847

3948
var subType = SubType("id-1")
40-
subType.field = 3
49+
subType.setFields(3)
4150

4251
repository.save(subType)
4352

0 commit comments

Comments
 (0)