diff --git a/pom.xml b/pom.xml
index eea61f492c..1bfe09b834 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.DATAMONGO-1685-SNAPSHOT
pom
Spring Data MongoDB
@@ -28,7 +28,7 @@
multi
spring-data-mongodb
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.DATACMNS-1058-SNAPSHOT
3.4.2
1.3.0
diff --git a/spring-data-mongodb-cross-store/pom.xml b/spring-data-mongodb-cross-store/pom.xml
index 4a49168713..e875aa4dcf 100644
--- a/spring-data-mongodb-cross-store/pom.xml
+++ b/spring-data-mongodb-cross-store/pom.xml
@@ -6,7 +6,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.DATAMONGO-1685-SNAPSHOT
../pom.xml
@@ -48,7 +48,7 @@
org.springframework.data
spring-data-mongodb
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.DATAMONGO-1685-SNAPSHOT
diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml
index 750ed23aa8..33c8488634 100644
--- a/spring-data-mongodb-distribution/pom.xml
+++ b/spring-data-mongodb-distribution/pom.xml
@@ -13,7 +13,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.DATAMONGO-1685-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb-log4j/pom.xml b/spring-data-mongodb-log4j/pom.xml
index 50d0a6454a..b610700d90 100644
--- a/spring-data-mongodb-log4j/pom.xml
+++ b/spring-data-mongodb-log4j/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.DATAMONGO-1685-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml
index 886bcca7b6..d5a019bf71 100644
--- a/spring-data-mongodb/pom.xml
+++ b/spring-data-mongodb/pom.xml
@@ -11,7 +11,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.DATAMONGO-1685-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java
index 1e0830d71b..3ea1c45737 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java
@@ -312,12 +312,13 @@ public List findAll(Example example) {
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
*/
@Override
- public S findOne(Example example) {
+ public Optional findOne(Example example) {
Assert.notNull(example, "Sample must not be null!");
Query q = new Query(new Criteria().alike(example));
- return mongoOperations.findOne(q, example.getProbeType(), entityInformation.getCollectionName());
+ return Optional
+ .ofNullable(mongoOperations.findOne(q, example.getProbeType(), entityInformation.getCollectionName()));
}
/*
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ContactRepositoryIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ContactRepositoryIntegrationTests.java
index 035050de37..ebb9dd4385 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ContactRepositoryIntegrationTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ContactRepositoryIntegrationTests.java
@@ -15,8 +15,7 @@
*/
package org.springframework.data.mongodb.repository;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
@@ -31,6 +30,7 @@
*
* @author Oliver Gierke
* @author Mark Paluch
+ * @author Christoph Strobl
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("config/MongoNamespaceIntegrationTests-context.xml")
@@ -49,7 +49,7 @@ public void readsAndWritesContactCorrectly() {
Person person = new Person("Oliver", "Gierke");
Contact result = repository.save(person);
- assertTrue(repository.findById(result.getId().toString()).get() instanceof Person);
+ assertThat(repository.findById(result.getId().toString())).containsInstanceOf(Person.class);
}
@Test // DATAMONGO-1245
@@ -57,6 +57,6 @@ public void findsContactByTypedExample() {
Person person = repository.save(new Person("Oliver", "Gierke"));
- assertThat(repository.findOne(Example.of(person)), instanceOf(Person.class));
+ assertThat(repository.findOne(Example.of(person))).containsInstanceOf(Person.class);
}
}
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 044df3a874..b7322abb17 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
@@ -15,8 +15,7 @@
*/
package org.springframework.data.mongodb.repository.support;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.domain.ExampleMatcher.*;
import java.util.ArrayList;
@@ -34,9 +33,9 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.ExampleMatcher.*;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
@@ -86,32 +85,28 @@ public void setUp() {
@Test
public void findALlFromCustomCollectionName() {
- List result = repository.findAll();
- assertThat(result, hasSize(all.size()));
+ assertThat(repository.findAll()).hasSize(all.size());
}
@Test
public void findOneFromCustomCollectionName() {
- Person result = repository.findById(dave.getId()).get();
- assertThat(result, is(dave));
+ assertThat(repository.findById(dave.getId()).get()).isEqualTo(dave);
}
@Test
public void deleteFromCustomCollectionName() {
+
repository.delete(dave);
- List result = repository.findAll();
- assertThat(result, hasSize(all.size() - 1));
- assertThat(result, not(hasItem(dave)));
+ assertThat(repository.findAll()).hasSize(all.size() - 1).doesNotContain(dave);
}
@Test
public void deleteByIdFromCustomCollectionName() {
+
repository.deleteById(dave.getId());
- List result = repository.findAll();
- assertThat(result, hasSize(all.size() - 1));
- assertThat(result, not(hasItem(dave)));
+ assertThat(repository.findAll()).hasSize(all.size() - 1).doesNotContain(dave);
}
@Test // DATAMONGO-1054
@@ -122,9 +117,7 @@ public void shouldInsertSingle() {
Person person1 = new Person("First1" + randomId, "Last2" + randomId, 42);
person1 = repository.insert(person1);
- Person saved = repository.findById(person1.getId()).get();
-
- assertThat(saved, is(equalTo(person1)));
+ assertThat(repository.findById(person1.getId())).contains(person1);
}
@Test // DATAMONGO-1054
@@ -142,7 +135,7 @@ public void shouldInsertMultipleFromList() {
List saved = repository.insert(persons);
- assertThat(saved, hasSize(persons.size()));
+ assertThat(saved).hasSize(persons.size());
assertThatAllReferencePersonsWereStoredCorrectly(idToPerson, saved);
}
@@ -161,7 +154,7 @@ public void shouldInsertMutlipleFromSet() {
List saved = repository.insert(persons);
- assertThat(saved, hasSize(persons.size()));
+ assertThat(saved).hasSize(persons.size());
assertThatAllReferencePersonsWereStoredCorrectly(idToPerson, saved);
}
@@ -174,9 +167,8 @@ public void findByExampleShouldLookUpEntriesCorrectly() {
Page result = repository.findAll(Example.of(sample), PageRequest.of(0, 10));
- assertThat(result.getContent(), hasItems(dave, oliver));
- assertThat(result.getContent(), hasSize(2));
- assertThat(result.getTotalPages(), is(1));
+ assertThat(result.getContent()).hasSize(2).contains(dave, oliver);
+ assertThat(result.getTotalPages()).isEqualTo(1);
}
@Test // DATAMONGO-1464
@@ -188,8 +180,8 @@ public void findByExampleMultiplePagesShouldLookUpEntriesCorrectly() {
Page result = repository.findAll(Example.of(sample), PageRequest.of(0, 1));
- assertThat(result.getContent(), hasSize(1));
- assertThat(result.getTotalPages(), is(2));
+ assertThat(result.getContent()).hasSize(1);
+ assertThat(result.getTotalPages()).isEqualTo(2);
}
@Test // DATAMONGO-1245
@@ -199,10 +191,7 @@ public void findAllByExampleShouldLookUpEntriesCorrectly() {
sample.setLastname("Matthews");
trimDomainType(sample, "id", "createdAt", "email");
- List result = repository.findAll(Example.of(sample));
-
- assertThat(result, containsInAnyOrder(dave, oliver));
- assertThat(result, hasSize(2));
+ assertThat(repository.findAll(Example.of(sample))).hasSize(2).contains(dave, oliver);
}
@Test // DATAMONGO-1245
@@ -218,10 +207,7 @@ public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObject()
sample.setAddress(dave.getAddress());
trimDomainType(sample, "id", "createdAt", "email");
- List result = repository.findAll(Example.of(sample));
-
- assertThat(result, hasItem(dave));
- assertThat(result, hasSize(1));
+ assertThat(repository.findAll(Example.of(sample))).hasSize(1).contains(dave);
}
@Test // DATAMONGO-1245
@@ -237,10 +223,7 @@ public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingPartialNestedOb
sample.setAddress(new Address(null, null, "Washington"));
trimDomainType(sample, "id", "createdAt", "email");
- List result = repository.findAll(Example.of(sample));
-
- assertThat(result, hasItems(dave, oliver));
- assertThat(result, hasSize(2));
+ assertThat(repository.findAll(Example.of(sample))).hasSize(2).contains(dave, oliver);
}
@Test // DATAMONGO-1245
@@ -254,9 +237,8 @@ public void findAllByExampleShouldNotFindEntriesWhenUsingPartialNestedObjectInSt
trimDomainType(sample, "id", "createdAt", "email");
Example example = Example.of(sample, matching().withIncludeNullValues());
- List result = repository.findAll(example);
- assertThat(result, empty());
+ assertThat(repository.findAll(example)).isEmpty();
}
@Test // DATAMONGO-1245
@@ -270,10 +252,8 @@ public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObjectInS
trimDomainType(sample, "id", "createdAt", "email");
Example example = Example.of(sample, matching().withIncludeNullValues());
- List result = repository.findAll(example);
- assertThat(result, hasItem(dave));
- assertThat(result, hasSize(1));
+ assertThat(repository.findAll(example)).hasSize(1).contains(dave);
}
@Test // DATAMONGO-1245
@@ -284,10 +264,8 @@ public void findAllByExampleShouldRespectStringMatchMode() {
trimDomainType(sample, "id", "createdAt", "email");
Example example = Example.of(sample, matching().withStringMatcher(StringMatcher.STARTING));
- List result = repository.findAll(example);
- assertThat(result, hasItems(dave, oliver));
- assertThat(result, hasSize(2));
+ assertThat(repository.findAll(example)).hasSize(2).contains(dave, oliver);
}
@Test // DATAMONGO-1245
@@ -307,10 +285,7 @@ public void findAllByExampleShouldResolveDbRefCorrectly() {
sample.setCreator(user);
trimDomainType(sample, "id", "createdAt", "email");
- List result = repository.findAll(Example.of(sample));
-
- assertThat(result, hasItem(megan));
- assertThat(result, hasSize(1));
+ assertThat(repository.findAll(Example.of(sample))).hasSize(1).contains(megan);
}
@Test // DATAMONGO-1245
@@ -325,10 +300,7 @@ public void findAllByExampleShouldResolveLegacyCoordinatesCorrectly() {
sample.setLocation(megan.getLocation());
trimDomainType(sample, "id", "createdAt", "email");
- List result = repository.findAll(Example.of(sample));
-
- assertThat(result, hasItem(megan));
- assertThat(result, hasSize(1));
+ assertThat(repository.findAll(Example.of(sample))).hasSize(1).contains(megan);
}
@Test // DATAMONGO-1245
@@ -343,10 +315,7 @@ public void findAllByExampleShouldResolveGeoJsonCoordinatesCorrectly() {
sample.setLocation(megan.getLocation());
trimDomainType(sample, "id", "createdAt", "email");
- List result = repository.findAll(Example.of(sample));
-
- assertThat(result, hasItem(megan));
- assertThat(result, hasSize(1));
+ assertThat(repository.findAll(Example.of(sample))).hasSize(1).contains(megan);
}
@Test // DATAMONGO-1245
@@ -362,10 +331,7 @@ public void findAllByExampleShouldProcessInheritanceCorrectly() {
trimDomainType(sample, "id", "createdAt", "email");
- List result = repository.findAll(Example.of(sample));
-
- assertThat(result, hasSize(1));
- assertThat(result, hasItem(reference));
+ assertThat(repository.findAll(Example.of(sample))).hasSize(1).contains(reference);
}
@Test // DATAMONGO-1245
@@ -376,9 +342,7 @@ public void findOneByExampleShouldLookUpEntriesCorrectly() {
sample.setLastname("Matthews");
trimDomainType(sample, "id", "createdAt", "email");
- Person result = repository.findOne(Example.of(sample));
-
- assertThat(result, is(equalTo(dave)));
+ assertThat(repository.findOne(Example.of(sample))).isPresent().contains(dave);
}
@Test // DATAMONGO-1245
@@ -389,9 +353,7 @@ public void existsByExampleShouldLookUpEntriesCorrectly() {
sample.setLastname("Matthews");
trimDomainType(sample, "id", "createdAt", "email");
- boolean result = repository.exists(Example.of(sample));
-
- assertThat(result, is(true));
+ assertThat(repository.exists(Example.of(sample))).isTrue();
}
@Test // DATAMONGO-1245
@@ -401,16 +363,14 @@ public void countByExampleShouldLookUpEntriesCorrectly() {
sample.setLastname("Matthews");
trimDomainType(sample, "id", "createdAt", "email");
- long result = repository.count(Example.of(sample));
-
- assertThat(result, is(equalTo(2L)));
+ assertThat(repository.count(Example.of(sample))).isEqualTo(2L);
}
private void assertThatAllReferencePersonsWereStoredCorrectly(Map references, List saved) {
for (Person person : saved) {
Person reference = references.get(person.getId());
- assertThat(person, is(equalTo(reference)));
+ assertThat(person).isEqualTo(reference);
}
}