From f6314a321af116cc64d7bded03174afab5a74db2 Mon Sep 17 00:00:00 2001 From: Ruben J Garcia Date: Tue, 20 Mar 2018 20:57:07 +0100 Subject: [PATCH] =?UTF-8?q?DATAMONGO-1907=20-=20Adjust=20SimpleReactiveMon?= =?UTF-8?q?goRepository.findOne(=E2=80=A6)=20to=20complete=20without=20exc?= =?UTF-8?q?eption=20on=20empty=20result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now no longer emit an exception via SimpleReactiveMongoRepository.findOne(Example) if the query completes without yielding a result. Previously findOne(Example) emitted a NoSuchElementException if the query returned no result. Original pull request: #541. --- .../support/SimpleReactiveMongoRepository.java | 3 ++- .../repository/SimpleReactiveMongoRepositoryTests.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java index 3a99ef5a8..ff412f9be 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java @@ -45,6 +45,7 @@ import org.springframework.util.Assert; * @author Mark Paluch * @author Oliver Gierke * @author Christoph Strobl + * @author Ruben J Garcia * @since 2.0 */ @RequiredArgsConstructor @@ -97,7 +98,7 @@ public class SimpleReactiveMongoRepository implement return Mono.error(new IncorrectResultSizeDataAccessException(1)); } return Mono.just(vals.iterator().next()); - }).single(); + }).next(); } /* 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 40685fddd..f01f53a33 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 @@ -54,6 +54,7 @@ import org.springframework.util.ClassUtils; * * @author Mark Paluch * @author Christoph Strobl + * @author Ruben J Garcia */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:reactive-infrastructure.xml") @@ -441,6 +442,14 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware, StepVerifier.create(repository.findOne(example)).expectError(IncorrectResultSizeDataAccessException.class); } + @Test // DATAMONGO-1907 + public void existsByExampleShouldReturnNonExistingWithoutThrowException() { + + Example example = Example.of(new ReactivePerson("foo", "bar", -1)); + + StepVerifier.create(repository.findOne(example)).verifyComplete(); + } + interface ReactivePersonRepostitory extends ReactiveMongoRepository { Flux findByLastname(String lastname);