Skip to content

Commit ebcaf7e

Browse files
DATAMONGO-2250 - Add test case for Kotlin override properties.
1 parent ff0887f commit ebcaf7e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.mongodb.core
17+
18+
import com.mongodb.MongoClient
19+
import org.junit.Test
20+
import org.springframework.data.mongodb.repository.MongoRepository
21+
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory
22+
import org.springframework.data.mongodb.test.util.Assertions.assertThat
23+
24+
open class SuperType(open val field: Int)
25+
26+
class SubType(val id: String, override var field: Int = 1) : SuperType(field)
27+
28+
interface MyRepository : MongoRepository<SubType, String>
29+
30+
class `KotlinOverridePropertyTests` {
31+
32+
val template = MongoTemplate(MongoClient(), "kotlin-tests")
33+
34+
@Test // DATAMONGO-2250
35+
fun `Ambiguous field mapping for override val field`() {
36+
37+
val repository = MongoRepositoryFactory(template).getRepository(MyRepository::class.java)
38+
39+
var subType = SubType("id-1")
40+
subType.field = 3
41+
42+
repository.save(subType)
43+
44+
assertThat(repository.findById(subType.id).get().field).isEqualTo(subType.field)
45+
}
46+
}

0 commit comments

Comments
 (0)