File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
main/java/org/springframework/data/mongodb/core/query
test/java/org/springframework/data/mongodb/core/query Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 28
28
* @author Oliver Gierke
29
29
* @author Christoph Strobl
30
30
* @author Thomas Darimont
31
+ * @author John Willemin
31
32
*/
32
33
public class BasicQuery extends Query {
33
34
@@ -70,7 +71,11 @@ public DBObject getQueryObject() {
70
71
71
72
@ Override
72
73
public DBObject getFieldsObject () {
73
- return fieldsObject ;
74
+ if (fieldsObject != null ) {
75
+ return fieldsObject ;
76
+ } else {
77
+ return super .getFieldsObject ();
78
+ }
74
79
}
75
80
76
81
@ Override
Original file line number Diff line number Diff line change 32
32
*
33
33
* @author Oliver Gierke
34
34
* @author Thomas Darimont
35
+ * @author John Willemin
35
36
*/
36
37
public class BasicQueryUnitTests {
37
38
@@ -137,4 +138,21 @@ public void handlesEqualsAndHashCodeCorrectlyWhenQuerySettingsDiffer() {
137
138
assertThat (query1 , is (not (equalTo (query2 ))));
138
139
assertThat (query1 .hashCode (), is (not (query2 .hashCode ())));
139
140
}
141
+
142
+ /**
143
+ * @see DATAMONGO-1387
144
+ */
145
+ @ Test
146
+ public void handlesFieldsIncludeCorrectly () {
147
+
148
+ String qry = "{ \" name\" : \" Thomas\" }" ;
149
+
150
+ BasicQuery query1 = new BasicQuery (qry );
151
+ query1 .fields ().include ("name" );
152
+
153
+ DBObject fieldsObject = query1 .getFieldsObject ();
154
+ fieldsObject .containsField ("name" );
155
+ assertThat (query1 .getFieldsObject (), notNullValue ());
156
+ assertThat (query1 .getFieldsObject ().containsField ("name" ), is (true ));
157
+ }
140
158
}
You can’t perform that action at this time.
0 commit comments