|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.core.convert;
|
17 | 17 |
|
18 |
| -import static org.hamcrest.Matchers.*; |
19 |
| -import static org.junit.Assert.*; |
20 |
| -import static org.mockito.Mockito.*; |
21 |
| -import static org.springframework.data.mongodb.core.DBObjectTestUtils.*; |
| 18 | +import static org.hamcrest.Matchers.arrayWithSize; |
| 19 | +import static org.hamcrest.Matchers.equalTo; |
| 20 | +import static org.hamcrest.Matchers.hasItem; |
| 21 | +import static org.hamcrest.Matchers.hasItems; |
| 22 | +import static org.hamcrest.Matchers.hasSize; |
| 23 | +import static org.hamcrest.Matchers.instanceOf; |
| 24 | +import static org.hamcrest.Matchers.is; |
| 25 | +import static org.hamcrest.Matchers.not; |
| 26 | +import static org.hamcrest.Matchers.notNullValue; |
| 27 | +import static org.hamcrest.Matchers.nullValue; |
| 28 | +import static org.junit.Assert.assertEquals; |
| 29 | +import static org.junit.Assert.assertThat; |
| 30 | +import static org.junit.Assert.assertTrue; |
| 31 | +import static org.junit.Assert.fail; |
| 32 | +import static org.mockito.Mockito.mock; |
| 33 | +import static org.mockito.Mockito.times; |
| 34 | +import static org.mockito.Mockito.verify; |
| 35 | +import static org.mockito.Mockito.when; |
| 36 | +import static org.springframework.data.mongodb.core.DBObjectTestUtils.getAsDBObject; |
| 37 | +import static org.springframework.data.mongodb.core.DBObjectTestUtils.getTypedValue; |
22 | 38 |
|
23 | 39 | import java.math.BigDecimal;
|
24 | 40 | import java.math.BigInteger;
|
|
50 | 66 | import org.junit.rules.ExpectedException;
|
51 | 67 | import org.junit.runner.RunWith;
|
52 | 68 | import org.mockito.Mock;
|
| 69 | +import org.mockito.Mockito; |
53 | 70 | import org.mockito.runners.MockitoJUnitRunner;
|
54 | 71 | import org.springframework.aop.framework.ProxyFactory;
|
55 | 72 | import org.springframework.beans.factory.annotation.Value;
|
@@ -1866,6 +1883,21 @@ public void rejectsBasicDbListToBeConvertedIntoComplexType() {
|
1866 | 1883 | converter.read(Item.class, source);
|
1867 | 1884 | }
|
1868 | 1885 |
|
| 1886 | + /** |
| 1887 | + * @see DATAMONGO-1058 |
| 1888 | + */ |
| 1889 | + @Test |
| 1890 | + public void readShouldRespectExplicitFieldNameForDbRef() { |
| 1891 | + |
| 1892 | + BasicDBObject source = new BasicDBObject(); |
| 1893 | + source.append("explict-name-for-db-ref", new DBRef(mock(DB.class), "foo", "1")); |
| 1894 | + |
| 1895 | + converter.read(ClassWithExplicitlyNamedDBRefProperty.class, source); |
| 1896 | + |
| 1897 | + verify(resolver, times(1)).resolveDbRef(Mockito.any(MongoPersistentProperty.class), Mockito.any(DBRef.class), |
| 1898 | + Mockito.any(DbRefResolverCallback.class)); |
| 1899 | + } |
| 1900 | + |
1869 | 1901 | static class GenericType<T> {
|
1870 | 1902 | T content;
|
1871 | 1903 | }
|
@@ -2116,4 +2148,16 @@ class ClassWithGeoShape {
|
2116 | 2148 |
|
2117 | 2149 | Shape shape;
|
2118 | 2150 | }
|
| 2151 | + |
| 2152 | + class ClassWithExplicitlyNamedDBRefProperty { |
| 2153 | + |
| 2154 | + @Field("explict-name-for-db-ref")// |
| 2155 | + @org.springframework.data.mongodb.core.mapping.DBRef// |
| 2156 | + ClassWithIntId dbRefProperty; |
| 2157 | + |
| 2158 | + public ClassWithIntId getDbRefProperty() { |
| 2159 | + return dbRefProperty; |
| 2160 | + } |
| 2161 | + |
| 2162 | + } |
2119 | 2163 | }
|
0 commit comments