Skip to content

Commit c28f725

Browse files
committed
DATAMONGO-1979 - Polishing.
Convert ReactiveMongoRepositoryTests to AssertJ. Add missing verifyComplete() steps to StepVerifier. Original pull request: #566.
1 parent a71f50f commit c28f725

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryMethod.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ public ReactiveMongoQueryMethod(Method method, RepositoryMetadata metadata, Proj
7979
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
8080
}
8181

82-
if (!multiWrapper && !singleWrapperWithWrappedPageableResult) {
82+
if (!multiWrapper) {
8383
throw new IllegalStateException(String.format(
8484
"Method has to use a either multi-item reactive wrapper return type or a wrapped Page/Slice type. Offending method: %s",
8585
method.toString()));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,9 +15,9 @@
1515
*/
1616
package org.springframework.data.mongodb.repository;
1717

18-
import static org.hamcrest.Matchers.*;
19-
import static org.junit.Assert.*;
18+
import static org.assertj.core.api.Assertions.offset;
2019
import static org.springframework.data.domain.Sort.Direction.*;
20+
import static org.springframework.data.mongodb.test.util.Assertions.assertThat;
2121

2222
import lombok.NoArgsConstructor;
2323
import reactor.core.Disposable;
@@ -128,12 +128,12 @@ public void shouldFindByLastName() {
128128

129129
@Test // DATAMONGO-1444
130130
public void shouldFindOneByLastName() {
131-
StepVerifier.create(repository.findOneByLastname(carter.getLastname())).expectNext(carter);
131+
StepVerifier.create(repository.findOneByLastname(carter.getLastname())).expectNext(carter).verifyComplete();
132132
}
133133

134134
@Test // DATAMONGO-1444
135135
public void shouldFindOneByPublisherOfLastName() {
136-
StepVerifier.create(repository.findByLastname(Mono.just(carter.getLastname()))).expectNext(carter);
136+
StepVerifier.create(repository.findByLastname(Mono.just(carter.getLastname()))).expectNext(carter).verifyComplete();
137137
}
138138

139139
@Test // DATAMONGO-1444
@@ -162,6 +162,7 @@ public void shouldFindUsingPublishersInStringQuery() {
162162

163163
@Test // DATAMONGO-1444
164164
public void shouldFindByLastNameAndSort() {
165+
165166
StepVerifier.create(repository.findByLastname("Matthews", Sort.by(ASC, "age"))) //
166167
.expectNext(oliver, dave) //
167168
.verifyComplete();
@@ -187,11 +188,11 @@ public void shouldUseTailableCursor() throws Exception {
187188

188189
Disposable disposable = cappedRepository.findByKey("value").doOnNext(documents::add).subscribe();
189190

190-
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
191+
assertThat(documents.poll(5, TimeUnit.SECONDS)).isNotNull();
191192

192193
StepVerifier.create(template.insert(new Capped("value", Math.random()))).expectNextCount(1).verifyComplete();
193-
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
194-
assertThat(documents.isEmpty(), is(true));
194+
assertThat(documents.poll(5, TimeUnit.SECONDS)).isNotNull();
195+
assertThat(documents).isEmpty();
195196

196197
disposable.dispose();
197198
}
@@ -213,16 +214,16 @@ public void shouldUseTailableCursorWithProjection() throws Exception {
213214
Disposable disposable = cappedRepository.findProjectionByKey("value").doOnNext(documents::add).subscribe();
214215

215216
CappedProjection projection1 = documents.poll(5, TimeUnit.SECONDS);
216-
assertThat(projection1, is(notNullValue()));
217-
assertThat(projection1.getRandom(), is(not(0)));
217+
assertThat(projection1).isNotNull();
218+
assertThat(projection1.getRandom()).isNotEqualTo(0);
218219

219220
StepVerifier.create(template.insert(new Capped("value", Math.random()))).expectNextCount(1).verifyComplete();
220221

221222
CappedProjection projection2 = documents.poll(5, TimeUnit.SECONDS);
222-
assertThat(projection2, is(notNullValue()));
223-
assertThat(projection2.getRandom(), is(not(0)));
223+
assertThat(projection2).isNotNull();
224+
assertThat(projection2.getRandom()).isNotEqualTo(0);
224225

225-
assertThat(documents.isEmpty(), is(true));
226+
assertThat(documents).isEmpty();
226227

227228
disposable.dispose();
228229
}
@@ -264,8 +265,8 @@ public void findsPeopleGeoresultByLocationWithinBox() {
264265
new Distance(2000, Metrics.KILOMETERS)) //
265266
).consumeNextWith(actual -> {
266267

267-
assertThat(actual.getDistance().getValue(), is(closeTo(1, 1)));
268-
assertThat(actual.getContent(), is(equalTo(dave)));
268+
assertThat(actual.getDistance().getValue()).isCloseTo(1, offset(1d));
269+
assertThat(actual.getContent()).isEqualTo(dave);
269270
}).verifyComplete();
270271
}
271272

@@ -282,8 +283,8 @@ public void findsPeoplePageableGeoresultByLocationWithinBox() {
282283
PageRequest.of(0, 10))) //
283284
.consumeNextWith(actual -> {
284285

285-
assertThat(actual.getDistance().getValue(), is(closeTo(1, 1)));
286-
assertThat(actual.getContent(), is(equalTo(dave)));
286+
assertThat(actual.getDistance().getValue()).isCloseTo(1, offset(1d));
287+
assertThat(actual.getContent()).isEqualTo(dave);
287288
}).verifyComplete();
288289
}
289290

0 commit comments

Comments
 (0)