|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.core.mapping;
|
17 | 17 |
|
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
18 | 19 | import static org.hamcrest.CoreMatchers.*;
|
19 |
| -import static org.junit.Assert.*; |
| 20 | +import static org.junit.Assert.assertThat; |
20 | 21 |
|
21 | 22 | import java.lang.annotation.ElementType;
|
22 | 23 | import java.lang.annotation.Retention;
|
23 | 24 | import java.lang.annotation.RetentionPolicy;
|
24 | 25 | import java.lang.annotation.Target;
|
25 | 26 | import java.lang.reflect.Field;
|
| 27 | +import java.util.ArrayList; |
| 28 | +import java.util.List; |
26 | 29 | import java.util.Locale;
|
27 | 30 |
|
28 | 31 | import org.junit.Before;
|
@@ -186,6 +189,19 @@ public void shouldConsiderComposedAnnotationsForFields() {
|
186 | 189 | assertThat(property.getFieldName(), is("myField"));
|
187 | 190 | }
|
188 | 191 |
|
| 192 | + @Test // DATAMONGO-1737 |
| 193 | + public void honorsFieldOrderWhenIteratingOverProperties() { |
| 194 | + |
| 195 | + MongoMappingContext context = new MongoMappingContext(); |
| 196 | + BasicMongoPersistentEntity<?> entity = context.getPersistentEntity(Sample.class); |
| 197 | + |
| 198 | + List<String> properties = new ArrayList<>(); |
| 199 | + |
| 200 | + entity.doWithProperties((MongoPersistentProperty property) -> properties.add(property.getName())); |
| 201 | + |
| 202 | + assertThat(properties).containsExactly("first", "second", "third"); |
| 203 | + } |
| 204 | + |
189 | 205 | private MongoPersistentProperty getPropertyFor(Field field) {
|
190 | 206 | return getPropertyFor(entity, field);
|
191 | 207 | }
|
@@ -213,6 +229,13 @@ class Person {
|
213 | 229 | @org.springframework.data.mongodb.core.mapping.Field(order = -20) String ssn;
|
214 | 230 | }
|
215 | 231 |
|
| 232 | + class Sample { |
| 233 | + |
| 234 | + @org.springframework.data.mongodb.core.mapping.Field(order = 2) String second; |
| 235 | + @org.springframework.data.mongodb.core.mapping.Field(order = 3) String third; |
| 236 | + @org.springframework.data.mongodb.core.mapping.Field(order = 1) String first; |
| 237 | + } |
| 238 | + |
216 | 239 | enum UppercaseFieldNamingStrategy implements FieldNamingStrategy {
|
217 | 240 |
|
218 | 241 | INSTANCE;
|
|
0 commit comments