|
1 | 1 | /*
|
2 |
| - * Copyright 2011-2014 the original author or authors. |
| 2 | + * Copyright 2011-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 | import static org.hamcrest.CoreMatchers.*;
|
19 | 19 | import static org.junit.Assert.*;
|
20 | 20 | import static org.springframework.data.mongodb.core.query.Criteria.*;
|
21 |
| -import nl.jqno.equalsverifier.EqualsVerifier; |
22 |
| -import nl.jqno.equalsverifier.Warning; |
| 21 | +import static org.springframework.data.mongodb.test.util.IsBsonObject.*; |
23 | 22 |
|
24 | 23 | import org.junit.Test;
|
25 | 24 | import org.springframework.data.domain.Sort.Direction;
|
26 | 25 |
|
27 | 26 | import com.mongodb.BasicDBObject;
|
28 | 27 | import com.mongodb.DBObject;
|
29 | 28 |
|
| 29 | +import nl.jqno.equalsverifier.EqualsVerifier; |
| 30 | +import nl.jqno.equalsverifier.Warning; |
| 31 | + |
30 | 32 | /**
|
31 | 33 | * Unit tests for {@link BasicQuery}.
|
32 | 34 | *
|
@@ -138,21 +140,48 @@ public void handlesEqualsAndHashCodeCorrectlyWhenQuerySettingsDiffer() {
|
138 | 140 | assertThat(query1, is(not(equalTo(query2))));
|
139 | 141 | assertThat(query1.hashCode(), is(not(query2.hashCode())));
|
140 | 142 | }
|
141 |
| - |
| 143 | + |
| 144 | + /** |
| 145 | + * @see DATAMONGO-1387 |
| 146 | + */ |
| 147 | + @Test |
| 148 | + public void returnsFieldsCorrectly() { |
| 149 | + |
| 150 | + String qry = "{ \"name\" : \"Thomas\"}"; |
| 151 | + String fields = "{\"name\":1, \"age\":1}"; |
| 152 | + |
| 153 | + BasicQuery query1 = new BasicQuery(qry, fields); |
| 154 | + |
| 155 | + assertThat(query1.getFieldsObject(), isBsonObject().containing("name").containing("age")); |
| 156 | + } |
| 157 | + |
142 | 158 | /**
|
143 | 159 | * @see DATAMONGO-1387
|
144 | 160 | */
|
145 | 161 | @Test
|
146 | 162 | public void handlesFieldsIncludeCorrectly() {
|
147 |
| - |
| 163 | + |
148 | 164 | String qry = "{ \"name\" : \"Thomas\"}";
|
149 |
| - |
| 165 | + |
150 | 166 | BasicQuery query1 = new BasicQuery(qry);
|
151 | 167 | 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)); |
| 168 | + |
| 169 | + assertThat(query1.getFieldsObject(), isBsonObject().containing("name")); |
157 | 170 | }
|
| 171 | + |
| 172 | + /** |
| 173 | + * @see DATAMONGO-1387 |
| 174 | + */ |
| 175 | + @Test |
| 176 | + public void combinesFieldsIncludeCorrectly() { |
| 177 | + |
| 178 | + String qry = "{ \"name\" : \"Thomas\"}"; |
| 179 | + String fields = "{\"name\":1, \"age\":1}"; |
| 180 | + |
| 181 | + BasicQuery query1 = new BasicQuery(qry, fields); |
| 182 | + query1.fields().include("gender"); |
| 183 | + |
| 184 | + assertThat(query1.getFieldsObject(), isBsonObject().containing("name").containing("age").containing("gender")); |
| 185 | + } |
| 186 | + |
158 | 187 | }
|
0 commit comments