diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
index 0d1ad25a1..dd978b5a8 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
@@ -348,7 +348,7 @@ public class Aggregation {
* @return
*/
public static SortOperation sort(Direction direction, String... fields) {
- return new SortOperation(new Sort(direction, fields));
+ return new SortOperation(Sort.by(direction, fields));
}
/**
@@ -585,7 +585,7 @@ public class Aggregation {
return command;
}
- /*
+ /*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java
index 35907ca7f..9be1bda31 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
* @author Thomas Darimont
* @author Oliver Gierke
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 1.3
* @see MongoDB Aggregation Framework: $sort
*/
@@ -40,7 +41,7 @@ public class SortOperation implements AggregationOperation {
/**
* Creates a new {@link SortOperation} for the given {@link Sort} instance.
- *
+ *
* @param sort must not be {@literal null}.
*/
public SortOperation(Sort sort) {
@@ -50,14 +51,14 @@ public class SortOperation implements AggregationOperation {
}
public SortOperation and(Direction direction, String... fields) {
- return and(new Sort(direction, fields));
+ return and(Sort.by(direction, fields));
}
public SortOperation and(Sort sort) {
return new SortOperation(this.sort.and(sort));
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
*/
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java
index 586efb346..5f946e6b4 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java
@@ -57,7 +57,6 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
-import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
@@ -1122,7 +1121,7 @@ public class MongoTemplateTests {
// test query with a sort
Query q2 = new Query(Criteria.where("age").gt(10));
- q2.with(new Sort(Direction.DESC, "age"));
+ q2.with(Sort.by(Direction.DESC, "age"));
PersonWithAList p5 = template.findOne(q2, PersonWithAList.class);
assertThat(p5.getFirstName(), is("Mark"));
}
@@ -2064,8 +2063,8 @@ public class MongoTemplateTests {
assertThat(template.count(query, Sample.class), is(1L));
- query.with(new PageRequest(0, 10));
- query.with(new Sort("field"));
+ query.with(PageRequest.of(0, 10));
+ query.with(Sort.by("field"));
assertThat(template.find(query, Sample.class), is(not(empty())));
}
@@ -2696,7 +2695,7 @@ public class MongoTemplateTests {
template.save(one);
template.save(two);
- Query query = query(where("_id").in("1", "2")).with(new Sort(Direction.DESC, "someIdKey"));
+ Query query = query(where("_id").in("1", "2")).with(Sort.by(Direction.DESC, "someIdKey"));
assertThat(template.find(query, DoucmentWithNamedIdField.class), contains(two, one));
}
@@ -2714,7 +2713,7 @@ public class MongoTemplateTests {
template.save(one);
template.save(two);
- Query query = query(where("_id").in("1", "2")).with(new Sort(Direction.DESC, "value"));
+ Query query = query(where("_id").in("1", "2")).with(Sort.by(Direction.DESC, "value"));
assertThat(template.find(query, DoucmentWithNamedIdField.class), contains(two, one));
}
@@ -2819,7 +2818,7 @@ public class MongoTemplateTests {
template.insertAll(Arrays.asList(oldestPerson, youngestPerson));
Query q = new Query();
- q.with(new Sort(Direction.ASC, "age"));
+ q.with(Sort.by(Direction.ASC, "age"));
CloseableIterator stream = template.stream(q, Person.class);
assertThat(stream.next().getAge(), is(youngestPerson.getAge()));
@@ -2835,7 +2834,7 @@ public class MongoTemplateTests {
template.insertAll(Arrays.asList(oldestPerson, youngestPerson));
Query q = new Query();
- q.with(new PageRequest(0, 1, new Sort(Direction.ASC, "age")));
+ q.with(PageRequest.of(0, 1, Sort.by(Direction.ASC, "age")));
CloseableIterator stream = template.stream(q, Person.class);
assertThat(stream.next().getAge(), is(youngestPerson.getAge()));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java
index 2bde06830..91302f057 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java
@@ -87,6 +87,7 @@ import com.mongodb.client.result.UpdateResult;
*
* @author Oliver Gierke
* @author Christoph Strobl
+ * @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
@@ -321,7 +322,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
@Test // DATAMONGO-948
public void sortShouldBeTakenAsIsWhenExecutingQueryWithoutSpecificTypeInformation() {
- Query query = Query.query(Criteria.where("foo").is("bar")).with(new Sort("foo"));
+ Query query = Query.query(Criteria.where("foo").is("bar")).with(Sort.by("foo"));
template.executeQuery(query, "collection1", new DocumentCallbackHandler() {
@Override
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SortOperationUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SortOperationUnitTests.java
index 7abaf7aca..4bc12b4e5 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SortOperationUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SortOperationUnitTests.java
@@ -26,15 +26,16 @@ import org.springframework.data.domain.Sort.Direction;
/**
* Unit tests for {@link SortOperation}.
- *
+ *
* @author Oliver Gierke
+ * @author Mark Paluch
*/
public class SortOperationUnitTests {
@Test
public void createsDocumentForAscendingSortCorrectly() {
- SortOperation operation = new SortOperation(new Sort(Direction.ASC, "foobar"));
+ SortOperation operation = new SortOperation(Sort.by(Direction.ASC, "foobar"));
Document result = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
Document sortValue = getAsDocument(result, "$sort");
@@ -45,7 +46,7 @@ public class SortOperationUnitTests {
@Test
public void createsDocumentForDescendingSortCorrectly() {
- SortOperation operation = new SortOperation(new Sort(Direction.DESC, "foobar"));
+ SortOperation operation = new SortOperation(Sort.by(Direction.DESC, "foobar"));
Document result = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
Document sortValue = getAsDocument(result, "$sort");
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java
index 268412617..b074ec212 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java
@@ -64,7 +64,7 @@ import com.mongodb.QueryBuilder;
/**
* Unit tests for {@link QueryMapper}.
- *
+ *
* @author Oliver Gierke
* @author Patryk Wasik
* @author Thomas Darimont
@@ -565,7 +565,7 @@ public class QueryMapperUnitTests {
@Test // DATAMONGO-647
public void customizedFieldNameShouldBeMappedCorrectlyWhenApplyingSort() {
- Query query = query(where("field").is("bar")).with(new Sort(Direction.DESC, "field"));
+ Query query = query(where("field").is("bar")).with(Sort.by(Direction.DESC, "field"));
org.bson.Document document = mapper.getMappedObject(query.getSortObject(),
context.getPersistentEntity(CustomizedField.class));
assertThat(document, equalTo(new org.bson.Document().append("foo", -1)));
@@ -597,7 +597,7 @@ public class QueryMapperUnitTests {
@Test // DATAMONGO-973
public void getMappedSortAppendsTextScoreProperlyWhenSortedByScore() {
- Query query = new Query().with(new Sort("textScore"));
+ Query query = new Query().with(Sort.by("textScore"));
org.bson.Document document = mapper.getMappedSort(query.getSortObject(),
context.getPersistentEntity(WithTextScoreProperty.class));
@@ -608,7 +608,7 @@ public class QueryMapperUnitTests {
@Test // DATAMONGO-973
public void getMappedSortIgnoresTextScoreWhenNotSortedByScore() {
- Query query = new Query().with(new Sort("id"));
+ Query query = new Query().with(Sort.by("id"));
org.bson.Document document = mapper.getMappedSort(query.getSortObject(),
context.getPersistentEntity(WithTextScoreProperty.class));
@@ -643,7 +643,7 @@ public class QueryMapperUnitTests {
@Test // DATAMONGO-1050
public void shouldUseExplicitlySetFieldnameForIdPropertyCandidatesUsedInSortClause() {
- Query query = new Query().with(new Sort("nested.id"));
+ Query query = new Query().with(Sort.by("nested.id"));
org.bson.Document document = mapper.getMappedSort(query.getSortObject(),
context.getPersistentEntity(RootForClassWithExplicitlyRenamedIdField.class));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java
index 6b6051002..74e2d2a17 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java
@@ -379,7 +379,7 @@ public class UpdateMapperUnitTests {
public void updatePushEachWithDocumentSortShouldRenderCorrectly() {
Update update = new Update().push("list")
- .sort(new Sort(new Order(Direction.ASC, "value"), new Order(Direction.ASC, "field")))
+ .sort(Sort.by(new Order(Direction.ASC, "value"), new Order(Direction.ASC, "field")))
.each(Collections.emptyList());
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(),
@@ -397,7 +397,7 @@ public class UpdateMapperUnitTests {
public void updatePushEachWithSortShouldRenderCorrectlyWhenUsingMultiplePush() {
Update update = new Update().push("authors").sort(Direction.ASC).each("Harry").push("chapters")
- .sort(new Sort(Direction.ASC, "order")).each(Collections.emptyList());
+ .sort(Sort.by(Direction.ASC, "order")).each(Collections.emptyList());
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Object.class));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java
index b1fe2099b..282aff875 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java
@@ -51,6 +51,7 @@ import com.mongodb.client.MongoCollection;
* @author Jon Brisbin
* @author Oliver Gierke
* @author Thomas Darimont
+ * @author Mark Paluch
*/
public class MappingTests extends AbstractIntegrationTests {
@@ -427,7 +428,7 @@ public class MappingTests extends AbstractIntegrationTests {
template.insert(p4);
Query q = query(where("id").in("1", "2"));
- q.with(new Sort(Direction.ASC, "id"));
+ q.with(Sort.by(Direction.ASC, "id"));
List people = template.find(q, PersonPojoStringId.class);
assertEquals(2, people.size());
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/NearQueryUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/NearQueryUnitTests.java
index 51be7494f..b2f284cea 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/NearQueryUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/NearQueryUnitTests.java
@@ -29,10 +29,11 @@ import org.springframework.data.mongodb.core.DocumentTestUtils;
/**
* Unit tests for {@link NearQuery}.
- *
+ *
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
+ * @author Mark Paluch
*/
public class NearQueryUnitTests {
@@ -86,7 +87,7 @@ public class NearQueryUnitTests {
@Test // DATAMONGO-445
public void shouldTakeSkipAndLimitSettingsFromGivenPageable() {
- Pageable pageable = new PageRequest(3, 5);
+ Pageable pageable = PageRequest.of(3, 5);
NearQuery query = NearQuery.near(new Point(1, 1)).with(pageable);
assertThat(query.getSkip(), is((long)pageable.getPageNumber() * pageable.getPageSize()));
@@ -110,7 +111,7 @@ public class NearQueryUnitTests {
int limit = 10;
int skip = 5;
- Pageable pageable = new PageRequest(3, 5);
+ Pageable pageable = PageRequest.of(3, 5);
NearQuery query = NearQuery.near(new Point(1, 1))
.query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip)).with(pageable);
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java
index f2b736018..18032fc5e 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java
@@ -40,6 +40,7 @@ import org.springframework.data.mongodb.core.SpecialDoc;
* @author Patryk Wasik
* @author Thomas Darimont
* @author Christoph Strobl
+ * @author Mark Paluch
*/
public class QueryTests {
@@ -190,7 +191,7 @@ public class QueryTests {
@Test // DATAMONGO-538
public void addsSortCorrectly() {
- Query query = new Query().with(new Sort(Direction.DESC, "foo"));
+ Query query = new Query().with(Sort.by(Direction.DESC, "foo"));
assertThat(query.getSortObject(), is(Document.parse("{ \"foo\" : -1}")));
}
@@ -200,7 +201,7 @@ public class QueryTests {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("foo");
- new Query().with(new Sort(new Sort.Order("foo").ignoreCase()));
+ new Query().with(Sort.by(new Sort.Order("foo").ignoreCase()));
}
@Test // DATAMONGO-709
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java
index 2d60564fc..8eede531b 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java
@@ -25,27 +25,30 @@ import org.springframework.data.domain.Sort.Direction;
/**
* Unit tests for sorting.
- *
+ *
* @author Oliver Gierke
+ * @author Mark Paluch
*/
public class SortTests {
@Test
public void testWithSortAscending() {
- Query s = new Query().with(new Sort(Direction.ASC, "name"));
+
+ Query s = new Query().with(Sort.by(Direction.ASC, "name"));
assertEquals(Document.parse("{ \"name\" : 1}"), s.getSortObject());
}
@Test
public void testWithSortDescending() {
- Query s = new Query().with(new Sort(Direction.DESC, "name"));
+
+ Query s = new Query().with(Sort.by(Direction.DESC, "name"));
assertEquals(Document.parse("{ \"name\" : -1}"), s.getSortObject());
}
@Test // DATADOC-177
public void preservesOrderKeysOnMultipleSorts() {
- Query sort = new Query().with(new Sort(Direction.DESC, "foo").and(new Sort(Direction.DESC, "bar")));
+ Query sort = new Query().with(Sort.by(Direction.DESC, "foo").and(Sort.by(Direction.DESC, "bar")));
assertThat(sort.getSortObject(), is(Document.parse("{ \"foo\" : -1 , \"bar\" : -1}")));
}
}
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryTests.java
index a7ed0265e..4a1d176c7 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryTests.java
@@ -47,6 +47,7 @@ import org.springframework.data.util.Version;
/**
* @author Christoph Strobl
+ * @author Mark Paluch
*/
public class TextQueryTests extends AbstractIntegrationTests {
@@ -207,12 +208,12 @@ public class TextQueryTests extends AbstractIntegrationTests {
// page 1
List result = template
- .find(new TextQuery("bake coffee cake").sortByScore().with(new PageRequest(0, 2)), FullTextDoc.class);
+ .find(new TextQuery("bake coffee cake").sortByScore().with(PageRequest.of(0, 2)), FullTextDoc.class);
assertThat(result, hasSize(2));
assertThat(result, contains(BAKE, COFFEE));
// page 2
- result = template.find(new TextQuery("bake coffee cake").sortByScore().with(new PageRequest(1, 2)),
+ result = template.find(new TextQuery("bake coffee cake").sortByScore().with(PageRequest.of(1, 2)),
FullTextDoc.class);
assertThat(result, hasSize(1));
assertThat(result, contains(CAKE));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryUnitTests.java
index b71b3c4ee..85f1b5643 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/TextQueryUnitTests.java
@@ -24,8 +24,9 @@ import org.springframework.data.domain.Sort.Direction;
/**
* Unit tests for {@link TextQuery}.
- *
+ *
* @author Christoph Strobl
+ * @author Mark Paluch
*/
public class TextQueryUnitTests {
@@ -65,7 +66,7 @@ public class TextQueryUnitTests {
public void shouldNotOverrideExistingSort() {
TextQuery query = new TextQuery(QUERY);
- query.with(new Sort(Direction.DESC, "foo"));
+ query.with(Sort.by(Direction.DESC, "foo"));
query.sortByScore();
assertThat(query,
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/gridfs/GridFsTemplateIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/gridfs/GridFsTemplateIntegrationTests.java
index 6f024adfe..9a881fbdd 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/gridfs/GridFsTemplateIntegrationTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/gridfs/GridFsTemplateIntegrationTests.java
@@ -45,7 +45,7 @@ import com.mongodb.gridfs.GridFSFile;
/**
* Integration tests for {@link GridFsTemplate}.
- *
+ *
* @author Oliver Gierke
* @author Philipp Schneider
* @author Thomas Darimont
@@ -151,7 +151,7 @@ public class GridFsTemplateIntegrationTests {
ObjectId third = operations.store(resource.getInputStream(), "foobar.xml");
ObjectId first = operations.store(resource.getInputStream(), "bar.xml");
- Query query = new Query().with(new Sort(Direction.ASC, "filename"));
+ Query query = new Query().with(Sort.by(Direction.ASC, "filename"));
List files = new ArrayList();
GridFSFindIterable result = operations.find(query);
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
index 4a3930796..92b257e66 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
@@ -63,7 +63,7 @@ import org.springframework.test.util.ReflectionTestUtils;
/**
* Base class for tests for {@link PersonRepository}.
- *
+ *
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
@@ -187,7 +187,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
public void findsPagedPersons() throws Exception {
- Page result = repository.findAll(new PageRequest(1, 2, Direction.ASC, "lastname", "firstname"));
+ Page result = repository.findAll(PageRequest.of(1, 2, Direction.ASC, "lastname", "firstname"));
assertThat(result.isFirst(), is(false));
assertThat(result.isLast(), is(false));
assertThat(result, hasItems(dave, stefan));
@@ -197,7 +197,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
public void executesPagedFinderCorrectly() throws Exception {
Page page = repository.findByLastnameLike("*a*",
- new PageRequest(0, 2, Direction.ASC, "lastname", "firstname"));
+ PageRequest.of(0, 2, Direction.ASC, "lastname", "firstname"));
assertThat(page.isFirst(), is(true));
assertThat(page.isLast(), is(false));
assertThat(page.getNumberOfElements(), is(2));
@@ -208,7 +208,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
public void executesPagedFinderWithAnnotatedQueryCorrectly() throws Exception {
Page page = repository.findByLastnameLikeWithPageable(".*a.*",
- new PageRequest(0, 2, Direction.ASC, "lastname", "firstname"));
+ PageRequest.of(0, 2, Direction.ASC, "lastname", "firstname"));
assertThat(page.isFirst(), is(true));
assertThat(page.isLast(), is(false));
assertThat(page.getNumberOfElements(), is(2));
@@ -345,7 +345,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
public void findsPagedPeopleByPredicate() throws Exception {
Page page = repository.findAll(person.lastname.contains("a"),
- new PageRequest(0, 2, Direction.ASC, "lastname"));
+ PageRequest.of(0, 2, Direction.ASC, "lastname"));
assertThat(page.isFirst(), is(true));
assertThat(page.isLast(), is(false));
assertThat(page.getNumberOfElements(), is(2));
@@ -364,7 +364,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test // DATAMONGO-446
public void findsPeopleBySexPaginated() {
- List males = repository.findBySex(Sex.MALE, new PageRequest(0, 2));
+ List males = repository.findBySex(Sex.MALE, PageRequest.of(0, 2));
assertThat(males.size(), is(2));
}
@@ -401,7 +401,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test // DATADOC-236
public void appliesStaticAndDynamicSorting() {
- List result = repository.findByFirstnameLikeOrderByLastnameAsc("*e*", new Sort("age"));
+ List result = repository.findByFirstnameLikeOrderByLastnameAsc("*e*", Sort.by("age"));
assertThat(result.size(), is(5));
assertThat(result.get(0), is(carter));
assertThat(result.get(1), is(stefan));
@@ -430,7 +430,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(dave);
GeoPage results = repository.findByLocationNear(new Point(-73.99, 40.73),
- new Distance(2000, Metrics.KILOMETERS), new PageRequest(0, 20));
+ new Distance(2000, Metrics.KILOMETERS), PageRequest.of(0, 20));
assertThat(results.getContent().isEmpty(), is(false));
// DATAMONGO-607
@@ -440,7 +440,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test // DATAMONGO-323
public void considersSortForAnnotatedQuery() {
- List result = repository.findByAgeLessThan(60, new Sort("firstname"));
+ List result = repository.findByAgeLessThan(60, Sort.by("firstname"));
assertThat(result.size(), is(7));
assertThat(result.get(0), is(alicia));
@@ -605,7 +605,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(Arrays.asList(dave, oliver, carter, boyd, leroi));
GeoPage results = repository.findByLocationNear(new Point(-73.99, 40.73),
- new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
+ new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
assertThat(results.getContent().isEmpty(), is(false));
assertThat(results.getNumberOfElements(), is(2));
@@ -627,7 +627,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(Arrays.asList(dave, oliver, carter));
GeoPage results = repository.findByLocationNear(new Point(-73.99, 40.73),
- new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
+ new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
assertThat(results.getContent().isEmpty(), is(false));
assertThat(results.getNumberOfElements(), is(1));
assertThat(results.isFirst(), is(false));
@@ -643,7 +643,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(dave);
GeoPage results = repository.findByLocationNear(new Point(-73.99, 40.73),
- new Distance(2000, Metrics.KILOMETERS), new PageRequest(0, 2));
+ new Distance(2000, Metrics.KILOMETERS), PageRequest.of(0, 2));
assertThat(results.getContent().isEmpty(), is(false));
assertThat(results.getNumberOfElements(), is(1));
@@ -659,7 +659,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(dave);
GeoPage results = repository.findByLocationNear(new Point(-73.99, 40.73),
- new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
+ new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
assertThat(results.getContent().isEmpty(), is(true));
assertThat(results.getNumberOfElements(), is(0));
@@ -722,7 +722,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test // DATAMONGO-870
public void findsSliceOfPersons() {
- Slice result = repository.findByAgeGreaterThan(40, new PageRequest(0, 2, Direction.DESC, "firstname"));
+ Slice result = repository.findByAgeGreaterThan(40, PageRequest.of(0, 2, Direction.DESC, "firstname"));
assertThat(result.hasNext(), is(true));
}
@@ -748,7 +748,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
alicia.creator = user;
repository.save(alicia);
- Page result = repository.findByHavingCreator(new PageRequest(0, 100));
+ Page result = repository.findByHavingCreator(PageRequest.of(0, 100));
assertThat(result.getNumberOfElements(), is(1));
assertThat(result.getContent().get(0), is(alicia));
@@ -817,7 +817,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(p);
- Page result = repository.findByAddressIn(Arrays.asList(adr), new PageRequest(0, 10));
+ Page result = repository.findByAddressIn(Arrays.asList(adr), PageRequest.of(0, 10));
assertThat(result.getContent(), hasSize(1));
}
@@ -831,7 +831,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(new Person("notfound", "bar"));
Page result = repository.findByCustomQueryFirstnamesAndLastname(Arrays.asList("bar", "foo", "fuu"), "bar",
- new PageRequest(0, 2));
+ PageRequest.of(0, 2));
assertThat(result.getContent(), hasSize(2));
assertThat(result.getTotalPages(), is(2));
@@ -847,7 +847,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(new Person("notfound", "notfound"));
Page result = repository.findByCustomQueryLastnameAndAddressStreetInList("bar",
- Arrays.asList("street1", "street2"), new PageRequest(0, 2));
+ Arrays.asList("street1", "street2"), PageRequest.of(0, 2));
assertThat(result.getContent(), hasSize(2));
assertThat(result.getTotalPages(), is(2));
@@ -869,7 +869,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
- Page result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(0, 2));
+ Page result = repository.findTop3ByLastnameStartingWith("Dylan", PageRequest.of(0, 2));
assertThat(result.getContent().size(), is(2));
assertThat(result.getTotalElements(), is(3L));
}
@@ -879,7 +879,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
- Page result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(1, 2));
+ Page result = repository.findTop3ByLastnameStartingWith("Dylan", PageRequest.of(1, 2));
assertThat(result.getContent().size(), is(1));
}
@@ -888,7 +888,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
- Page result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(100, 2));
+ Page result = repository.findTop3ByLastnameStartingWith("Dylan", PageRequest.of(100, 2));
assertThat(result.getContent().size(), is(0));
assertThat(result.getTotalElements(), is(3L));
}
@@ -896,7 +896,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test // DATAMONGO-996, DATAMONGO-950, DATAMONGO-1464
public void gettingNonFirstPageWorksWithoutLimitBeingSet() {
- Page slice = repository.findByLastnameLike("Matthews", new PageRequest(1, 1));
+ Page slice = repository.findByLastnameLike("Matthews", PageRequest.of(1, 1));
assertThat(slice.getContent(), hasSize(1));
assertThat(slice.hasPrevious(), is(true));
@@ -948,7 +948,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(persons);
- Slice slice = repository.findByAgeGreaterThan(50, new PageRequest(0, 20, Direction.ASC, "firstname"));
+ Slice slice = repository.findByAgeGreaterThan(50, PageRequest.of(0, 20, Direction.ASC, "firstname"));
assertThat(slice, contains(persons.subList(0, 20).toArray()));
slice = repository.findByAgeGreaterThan(50, slice.nextPageable());
@@ -1010,7 +1010,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(persons);
- PageRequest pageRequest = new PageRequest(0, 2, new QSort(person.address.street.desc()));
+ PageRequest pageRequest = PageRequest.of(0, 2, new QSort(person.address.street.desc()));
Iterable result = repository.findAll(pageRequest);
assertThat(result, is(Matchers. iterableWithSize(2)));
@@ -1102,7 +1102,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
ReflectionTestUtils.setField(sample, "createdAt", null);
ReflectionTestUtils.setField(sample, "email", null);
- Page result = repository.findAll(Example.of(sample), new PageRequest(0, 10));
+ Page result = repository.findAll(Example.of(sample), PageRequest.of(0, 10));
assertThat(result.getNumberOfElements(), is(2));
}
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java
index a3a879120..cb5dd2971 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/MongoRepositoryTextSearchIntegrationTests.java
@@ -58,6 +58,7 @@ import com.mongodb.MongoClient;
*
* @author Christoph Strobl
* @author Oliver Gierke
+ * @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -122,7 +123,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
initRepoWithDefaultDocuments();
- Page page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("film"), new PageRequest(1,
+ Page page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("film"), PageRequest.of(1,
1, Direction.ASC, "id"));
assertThat(page.hasNext(), is(true));
@@ -138,7 +139,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
repo.save(snipes);
- List result = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), new Sort(
+ List result = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), Sort.by(
"score"));
assertThat(result.size(), is(4));
@@ -152,7 +153,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
repo.save(snipes);
- Page page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), new PageRequest(
+ Page page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), PageRequest.of(
0, 10, Direction.ASC, "score"));
assertThat(page.getTotalElements(), is(4L));
@@ -166,7 +167,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
repo.save(snipes);
- Page page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), new PageRequest(
+ Page page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), PageRequest.of(
0, 10, Direction.ASC, "id"));
assertThat(page.getTotalElements(), is(4L));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/RedeclaringRepositoryMethodsTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/RedeclaringRepositoryMethodsTests.java
index aced3f412..9083a8baf 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/RedeclaringRepositoryMethodsTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/RedeclaringRepositoryMethodsTests.java
@@ -28,6 +28,7 @@ import org.springframework.test.context.ContextConfiguration;
/**
* @author Thomas Darimont
+ * @author Mark Paluch
*/
@ContextConfiguration("config/MongoNamespaceIntegrationTests-context.xml")
public class RedeclaringRepositoryMethodsTests extends AbstractPersonRepositoryIntegrationTests {
@@ -37,7 +38,7 @@ public class RedeclaringRepositoryMethodsTests extends AbstractPersonRepositoryI
@Test // DATAMONGO-760
public void adjustedWellKnownPagedFindAllMethodShouldReturnOnlyTheUserWithFirstnameOliverAugust() {
- Page page = repository.findAll(new PageRequest(0, 2));
+ Page page = repository.findAll(PageRequest.of(0, 2));
assertThat(page.getNumberOfElements(), is(1));
assertThat(page.getContent().get(0).getFirstname(), is(oliver.getFirstname()));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java
index 8d3a1aead..f4be5770f 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java
@@ -163,7 +163,7 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
@Test // DATAMONGO-1444
public void findAllWithSortShouldReturnResults() {
- StepVerifier.create(repository.findAll(new Sort(new Order(Direction.ASC, "age")))) //
+ StepVerifier.create(repository.findAll(Sort.by(new Order(Direction.ASC, "age")))) //
.expectNextCount(7) //
.verifyComplete();
}
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java
index 1a243deaa..6a97cbf6f 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java
@@ -62,7 +62,7 @@ import com.mongodb.client.result.DeleteResult;
/**
* Unit tests for {@link AbstractMongoQuery}.
- *
+ *
* @author Christoph Strobl
* @author Oliver Gierke
* @author Thomas Darimont
@@ -152,7 +152,7 @@ public class AbstractMongoQueryUnitTests {
public void metadataShouldBeAddedToQueryCorrectly() {
MongoQueryFake query = createQueryForMethod("findByFirstname", String.class, Pageable.class);
- query.execute(new Object[] { "fake", new PageRequest(0, 10) });
+ query.execute(new Object[] { "fake", PageRequest.of(0, 10) });
ArgumentCaptor captor = ArgumentCaptor.forClass(Query.class);
@@ -164,7 +164,7 @@ public class AbstractMongoQueryUnitTests {
public void metadataShouldBeAddedToCountQueryCorrectly() {
MongoQueryFake query = createQueryForMethod("findByFirstname", String.class, Pageable.class);
- query.execute(new Object[] { "fake", new PageRequest(1, 10) });
+ query.execute(new Object[] { "fake", PageRequest.of(1, 10) });
ArgumentCaptor captor = ArgumentCaptor.forClass(Query.class);
@@ -176,7 +176,7 @@ public class AbstractMongoQueryUnitTests {
public void metadataShouldBeAddedToStringBasedQueryCorrectly() {
MongoQueryFake query = createQueryForMethod("findByAnnotatedQuery", String.class, Pageable.class);
- query.execute(new Object[] { "fake", new PageRequest(0, 10) });
+ query.execute(new Object[] { "fake", PageRequest.of(0, 10) });
ArgumentCaptor captor = ArgumentCaptor.forClass(Query.class);
@@ -188,7 +188,7 @@ public class AbstractMongoQueryUnitTests {
public void slicedExecutionShouldRetainNrOfElementsToSkip() {
MongoQueryFake query = createQueryForMethod("findByLastname", String.class, Pageable.class);
- Pageable page1 = new PageRequest(0, 10);
+ Pageable page1 = PageRequest.of(0, 10);
Pageable page2 = page1.next();
query.execute(new Object[] { "fake", page1 });
@@ -206,7 +206,7 @@ public class AbstractMongoQueryUnitTests {
public void slicedExecutionShouldIncrementLimitByOne() {
MongoQueryFake query = createQueryForMethod("findByLastname", String.class, Pageable.class);
- Pageable page1 = new PageRequest(0, 10);
+ Pageable page1 = PageRequest.of(0, 10);
Pageable page2 = page1.next();
query.execute(new Object[] { "fake", page1 });
@@ -224,7 +224,7 @@ public class AbstractMongoQueryUnitTests {
public void slicedExecutionShouldRetainSort() {
MongoQueryFake query = createQueryForMethod("findByLastname", String.class, Pageable.class);
- Pageable page1 = new PageRequest(0, 10, Sort.Direction.DESC, "bar");
+ Pageable page1 = PageRequest.of(0, 10, Sort.Direction.DESC, "bar");
Pageable page2 = page1.next();
query.execute(new Object[] { "fake", page1 });
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryExecutionUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryExecutionUnitTests.java
index 22a3c84ab..54ef9ed59 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryExecutionUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryExecutionUnitTests.java
@@ -55,7 +55,7 @@ import org.springframework.util.ReflectionUtils;
/**
* Unit tests for {@link MongoQueryExecution}.
- *
+ *
* @author Mark Paluch
* @soundtrack U Can't Touch This - MC Hammer
*/
@@ -88,7 +88,7 @@ public class MongoQueryExecutionUnitTests {
when(mongoOperationsMock.find(any(Query.class), eq(Person.class), eq("person")))
.thenReturn(Collections. emptyList());
- PagedExecution execution = new PagedExecution(mongoOperationsMock, new PageRequest(0, 10));
+ PagedExecution execution = new PagedExecution(mongoOperationsMock, PageRequest.of(0, 10));
execution.execute(new Query(), Person.class, "person");
verify(mongoOperationsMock).find(any(Query.class), eq(Person.class), eq("person"));
@@ -101,7 +101,7 @@ public class MongoQueryExecutionUnitTests {
when(mongoOperationsMock.find(any(Query.class), eq(Person.class), eq("person")))
.thenReturn(Arrays.asList(new Person(), new Person(), new Person(), new Person()));
- PagedExecution execution = new PagedExecution(mongoOperationsMock, new PageRequest(0, 10));
+ PagedExecution execution = new PagedExecution(mongoOperationsMock, PageRequest.of(0, 10));
execution.execute(new Query(), Person.class, "person");
verify(mongoOperationsMock).find(any(Query.class), eq(Person.class), eq("person"));
@@ -114,7 +114,7 @@ public class MongoQueryExecutionUnitTests {
when(mongoOperationsMock.find(any(Query.class), eq(Person.class), eq("person")))
.thenReturn(Collections. emptyList());
- PagedExecution execution = new PagedExecution(mongoOperationsMock, new PageRequest(2, 10));
+ PagedExecution execution = new PagedExecution(mongoOperationsMock, PageRequest.of(2, 10));
execution.execute(new Query(), Person.class, "person");
verify(mongoOperationsMock).find(any(Query.class), eq(Person.class), eq("person"));
@@ -125,7 +125,7 @@ public class MongoQueryExecutionUnitTests {
public void pagingGeoExecutionShouldUseCountFromResultWithOffsetAndResultsWithinPageSize() throws Exception {
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod,
- new Object[] { POINT, DISTANCE, new PageRequest(0, 10) });
+ new Object[] { POINT, DISTANCE, PageRequest.of(0, 10) });
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock);
GeoResult result = new GeoResult(new Person(), DISTANCE);
@@ -145,7 +145,7 @@ public class MongoQueryExecutionUnitTests {
public void pagingGeoExecutionRetrievesObjectsForPageableOutOfRange() throws Exception {
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod,
- new Object[] { POINT, DISTANCE, new PageRequest(2, 10) });
+ new Object[] { POINT, DISTANCE, PageRequest.of(2, 10) });
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock);
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecutionUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecutionUnitTests.java
index 79c00309d..9723de421 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecutionUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecutionUnitTests.java
@@ -60,7 +60,7 @@ public class ReactiveMongoQueryExecutionUnitTests {
Query query = new Query();
when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
when(parameterAccessor.getDistanceRange()).thenReturn(new Range<>(new Distance(10), new Distance(15)));
- when(parameterAccessor.getPageable()).thenReturn(new PageRequest(1, 10));
+ when(parameterAccessor.getPageable()).thenReturn(PageRequest.of(1, 10));
new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query,
Person.class, "person");
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/QueryDslMongoRepositoryIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/QueryDslMongoRepositoryIntegrationTests.java
index de30bf44d..fb9e8e4c9 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/QueryDslMongoRepositoryIntegrationTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/QueryDslMongoRepositoryIntegrationTests.java
@@ -38,8 +38,9 @@ import com.querydsl.core.types.Predicate;
/**
* Integration test for {@link QueryDslMongoRepository}.
- *
+ *
* @author Thomas Darimont
+ * @author Mark Paluch
*/
@ContextConfiguration(
locations = "/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml")
@@ -81,7 +82,7 @@ public class QueryDslMongoRepositoryIntegrationTests {
@Test // DATAMONGO-1167
public void shouldSupportFindAllWithPredicateAndSort() {
- List users = repository.findAll(person.lastname.isNotNull(), new Sort(Direction.ASC, "firstname"));
+ List users = repository.findAll(person.lastname.isNotNull(), Sort.by(Direction.ASC, "firstname"));
assertThat(users, hasSize(3));
assertThat(users.get(0).getFirstname(), is(carter.getFirstname()));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepositoryTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepositoryTests.java
index 5ab3ba9c4..283fbdfa2 100755
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepositoryTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepositoryTests.java
@@ -51,7 +51,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.util.ReflectionTestUtils;
/**
- * @author A. B. M. Kowser
+ * @author A. B. M. Kowser
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
@@ -172,7 +172,7 @@ public class SimpleMongoRepositoryTests {
sample.setLastname("Matthews");
trimDomainType(sample, "id", "createdAt", "email");
- Page result = repository.findAll(Example.of(sample), new PageRequest(0, 10));
+ Page result = repository.findAll(Example.of(sample), PageRequest.of(0, 10));
assertThat(result.getContent(), hasItems(dave, oliver));
assertThat(result.getContent(), hasSize(2));
@@ -186,7 +186,7 @@ public class SimpleMongoRepositoryTests {
sample.setLastname("Matthews");
trimDomainType(sample, "id", "createdAt", "email");
- Page result = repository.findAll(Example.of(sample), new PageRequest(0, 1));
+ Page result = repository.findAll(Example.of(sample), PageRequest.of(0, 1));
assertThat(result.getContent(), hasSize(1));
assertThat(result.getTotalPages(), is(2));
diff --git a/src/main/asciidoc/reference/mongo-repositories.adoc b/src/main/asciidoc/reference/mongo-repositories.adoc
index ca0b9c6b3..095f25438 100644
--- a/src/main/asciidoc/reference/mongo-repositories.adoc
+++ b/src/main/asciidoc/reference/mongo-repositories.adoc
@@ -114,7 +114,7 @@ public class PersonRepositoryTests {
@Test
public void readsFirstPageCorrectly() {
- Page persons = repository.findAll(new PageRequest(0, 10));
+ Page persons = repository.findAll(PageRequest.of(0, 10));
assertThat(persons.isFirstPage(), is(true));
}
}
@@ -463,7 +463,7 @@ QPerson person = new QPerson("person");
List result = repository.findAll(person.address.zipCode.eq("C0123"));
Page page = repository.findAll(person.lastname.contains("a"),
- new PageRequest(0, 2, Direction.ASC, "lastname"));
+ PageRequest.of(0, 2, Direction.ASC, "lastname"));
----
`QPerson` is a class that is generated (via the Java annotation post processing tool) which is a `Predicate` that allows you to write type safe queries. Notice that there are no strings in the query other than the value "C0123".
@@ -528,12 +528,12 @@ interface FullTextRepository extends Repository {
}
-Sort sort = new Sort("score");
+Sort sort = Sort.by("score");
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("spring", "data");
List result = repository.findAllBy(criteria, sort);
criteria = TextCriteria.forDefaultLanguage().matching("film");
-Page page = repository.findAllBy(criteria, new PageRequest(1, 1, sort));
+Page page = repository.findAllBy(criteria, PageRequest.of(1, 1, sort));
List result = repository.findByTitleOrderByScoreDesc("mongodb", criteria);
----
diff --git a/src/main/asciidoc/reference/reactive-mongo-repositories.adoc b/src/main/asciidoc/reference/reactive-mongo-repositories.adoc
index c33b6511a..3295a4e0c 100644
--- a/src/main/asciidoc/reference/reactive-mongo-repositories.adoc
+++ b/src/main/asciidoc/reference/reactive-mongo-repositories.adoc
@@ -105,7 +105,7 @@ public class PersonRepositoryTests {
@Test
public void sortsElementsCorrectly() {
- Flux persons = repository.findAll(new Sort(new Order(ASC, "lastname")));
+ Flux persons = repository.findAll(Sort.by(new Order(ASC, "lastname")));
}
}
----