Skip to content

Commit e66d317

Browse files
christophstroblmp911de
authored andcommitted
Polishing.
Replace usage of StepVerifier.create with StepVerifier::create. Original pull request: #672 See #671
1 parent f98c7b9 commit e66d317

File tree

8 files changed

+58
-26
lines changed

8 files changed

+58
-26
lines changed

cassandra/reactive/src/test/java/example/springdata/cassandra/people/ReactiveCassandraTemplateIntegrationTest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ void setUp() {
4848
new Person("Jesse", "Pinkman", 27))) //
4949
.flatMap(template::insert);
5050

51-
StepVerifier.create(truncateAndInsert).expectNextCount(4).verifyComplete();
51+
truncateAndInsert.as(StepVerifier::create) //
52+
.expectNextCount(4) //
53+
.verifyComplete();
5254
}
5355

5456
/**
@@ -67,6 +69,8 @@ void shouldInsertAndCountData() {
6769
.flatMap(v -> template.count(Person.class)) //
6870
.doOnNext(System.out::println);
6971

70-
StepVerifier.create(saveAndCount).expectNext(6L).verifyComplete();
72+
saveAndCount.as(StepVerifier::create) //
73+
.expectNext(6L) //
74+
.verifyComplete();
7175
}
7276
}

cassandra/reactive/src/test/java/example/springdata/cassandra/people/ReactivePersonRepositoryIntegrationTest.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ void setUp() {
5050
new Person("Saul", "Goodman", 42), //
5151
new Person("Jesse", "Pinkman", 27))));
5252

53-
StepVerifier.create(deleteAndInsert).expectNextCount(4).verifyComplete();
53+
deleteAndInsert.as(StepVerifier::create) //
54+
.expectNextCount(4) //
55+
.verifyComplete();
5456
}
5557

5658
/**
@@ -67,7 +69,9 @@ void shouldInsertAndCountData() {
6769
.flatMap(v -> repository.count()) //
6870
.doOnNext(System.out::println);
6971

70-
StepVerifier.create(saveAndCount).expectNext(6L).verifyComplete();
72+
saveAndCount.as(StepVerifier::create) //
73+
.expectNext(6L) //
74+
.verifyComplete();
7175
}
7276

7377
/**
@@ -77,7 +81,7 @@ void shouldInsertAndCountData() {
7781
@Test
7882
void shouldPerformConversionBeforeResultProcessing() {
7983

80-
StepVerifier.create(repository.findAll().doOnNext(System.out::println)) //
84+
repository.findAll().doOnNext(System.out::println).as(StepVerifier::create) //
8185
.expectNextCount(4) //
8286
.verifyComplete();
8387
}
@@ -87,31 +91,43 @@ void shouldPerformConversionBeforeResultProcessing() {
8791
*/
8892
@Test
8993
void shouldQueryDataWithQueryDerivation() {
90-
StepVerifier.create(repository.findByLastname("White")).expectNextCount(2).verifyComplete();
94+
95+
repository.findByLastname("White").as(StepVerifier::create) //
96+
.expectNextCount(2) //
97+
.verifyComplete();
9198
}
9299

93100
/**
94101
* Fetch data limiting result size.
95102
*/
96103
@Test
97104
void limitResultSize() {
98-
StepVerifier.create(repository.findByLastname("White", Limit.of(1))).expectNextCount(1).verifyComplete();
105+
106+
repository.findByLastname("White", Limit.of(1)).as(StepVerifier::create) //
107+
.expectNextCount(1) //
108+
.verifyComplete();
99109
}
100110

101111
/**
102112
* Fetch data using a string query.
103113
*/
104114
@Test
105115
void shouldQueryDataWithStringQuery() {
106-
StepVerifier.create(repository.findByFirstnameInAndLastname("Walter", "White")).expectNextCount(1).verifyComplete();
116+
117+
repository.findByFirstnameInAndLastname("Walter", "White").as(StepVerifier::create) //
118+
.expectNextCount(1) //
119+
.verifyComplete();
107120
}
108121

109122
/**
110123
* Fetch data using query derivation.
111124
*/
112125
@Test
113126
void shouldQueryDataWithDeferredQueryDerivation() {
114-
StepVerifier.create(repository.findByLastname(Mono.just("White"))).expectNextCount(2).verifyComplete();
127+
128+
repository.findByLastname(Mono.just("White")).as(StepVerifier::create) //
129+
.expectNextCount(2) //
130+
.verifyComplete();
115131
}
116132

117133
/**
@@ -120,7 +136,7 @@ void shouldQueryDataWithDeferredQueryDerivation() {
120136
@Test
121137
void shouldQueryDataWithMixedDeferredQueryDerivation() {
122138

123-
StepVerifier.create(repository.findByFirstnameAndLastname(Mono.just("Walter"), "White")) //
139+
repository.findByFirstnameAndLastname(Mono.just("Walter"), "White").as(StepVerifier::create) //
124140
.expectNextCount(1) //
125141
.verifyComplete();
126142
}

mongodb/change-streams/src/test/java/example/springdata/mongodb/ChangeStreamsTests.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -200,28 +200,31 @@ public void reactiveChangeEvents() {
200200
ChangeStreamOptions.builder().filter(newAggregation(match(where("operationType").is("insert")))).build(),
201201
Person.class);
202202

203-
StepVerifier.create(changeStream) //
203+
changeStream.as(StepVerifier::create) //
204204
.expectSubscription() //
205205
.expectNoEvent(Duration.ofMillis(200)) // wait till change streams becomes active
206206

207207
// Save documents and await their change events
208208
.then(() -> {
209-
StepVerifier.create(reactiveTemplate.save(gabriel)).expectNextCount(1).verifyComplete();
210-
StepVerifier.create(reactiveTemplate.save(ash)).expectNextCount(1).verifyComplete();
209+
reactiveTemplate.save(gabriel).as(StepVerifier::create).expectNextCount(1).verifyComplete();
210+
reactiveTemplate.save(ash).as(StepVerifier::create).expectNextCount(1).verifyComplete();
211211
}).expectNextCount(2) //
212212

213213
// Update a document
214214
.then(() -> {
215215

216-
StepVerifier.create(reactiveTemplate.update(Person.class) //
216+
reactiveTemplate.update(Person.class) //
217217
.matching(query(where("id").is(ash.id()))) //
218218
.apply(update("age", 40)) //
219-
.first()).expectNextCount(1).verifyComplete();
219+
.first() //
220+
.as(StepVerifier::create) //
221+
.expectNextCount(1) //
222+
.verifyComplete();
220223
}).expectNoEvent(Duration.ofMillis(200)) // updates are skipped
221224

222225
// Save another document and await its change event
223226
.then(() -> {
224-
StepVerifier.create(reactiveTemplate.save(michael)).expectNextCount(1).verifyComplete();
227+
reactiveTemplate.save(michael).as(StepVerifier::create).expectNextCount(1).verifyComplete();
225228
}).expectNextCount(1) // there we go, all events received.
226229

227230
.thenCancel() // change streams are infinite streams, at some point we need to unsubscribe

mongodb/reactive/src/test/java/example/springdata/mongodb/people/ReactiveMongoTemplateIntegrationTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static void setProperties(DynamicPropertyRegistry registry) {
6060
@BeforeEach
6161
void setUp() {
6262

63-
StepVerifier.create(template.dropCollection(Person.class)).verifyComplete();
63+
template.dropCollection(Person.class).as(StepVerifier::create) //
64+
.verifyComplete();
6465

6566
var insertAll = template
6667
.insertAll(Flux.just(new Person("Walter", "White", 50), //

redis/reactive/src/test/java/example/springdata/redis/commands/KeyCommandsTests.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void iterateOverKeysMatchingPrefixUsingKeysCommand() {
7777
.count() //
7878
.doOnSuccess(count -> System.out.println(String.format("Total No. found: %s", count)));
7979

80-
StepVerifier.create(keyCount).expectNext(50L).verifyComplete();
80+
keyCount.as(StepVerifier::create).expectNext(50L).verifyComplete();
8181
}
8282

8383
/**
@@ -98,7 +98,7 @@ void storeToListAndPop() {
9898
.flatMap(result -> llen) //
9999
.doOnNext(count -> System.out.println(String.format("Total items in list left: %s", count)));//
100100

101-
StepVerifier.create(popAndLlen).expectNext(0L).verifyComplete();
101+
popAndLlen.as(StepVerifier::create).expectNext(0L).verifyComplete();
102102
}
103103

104104
private void generateRandomKeys(int nrKeys) {
@@ -109,7 +109,9 @@ private void generateRandomKeys(int nrKeys) {
109109
.map(key -> SetCommand.set(key) //
110110
.value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes())));
111111

112-
StepVerifier.create(connection.stringCommands().set(generator)).expectNextCount(nrKeys).verifyComplete();
112+
connection.stringCommands().set(generator).as(StepVerifier::create) //
113+
.expectNextCount(nrKeys) //
114+
.verifyComplete();
113115

114116
}
115117

redis/reactive/src/test/java/example/springdata/redis/operations/JacksonJsonTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class JacksonJsonTests {
5656
@Test
5757
void shouldWriteAndReadPerson() {
5858

59-
StepVerifier.create(typedOperations.opsForValue().set("homer", new Person("Homer", "Simpson"))) //
59+
typedOperations.opsForValue().set("homer", new Person("Homer", "Simpson")).as(StepVerifier::create) //
6060
.expectNext(true) //
6161
.verifyComplete();
6262

redis/reactive/src/test/java/example/springdata/redis/operations/ListOperationsTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ class ListOperationsTests {
4545

4646
@BeforeEach
4747
void before() {
48-
StepVerifier.create(operations.execute(it -> it.serverCommands().flushDb())).expectNext("OK").verifyComplete();
48+
49+
operations.execute(it -> it.serverCommands().flushDb()).as(StepVerifier::create) //
50+
.expectNext("OK") //
51+
.verifyComplete();
4952
}
5053

5154
/**
@@ -63,7 +66,7 @@ void shouldPollAndPopulateQueue() {
6366
.log("example.springdata.redis", Level.INFO);
6467

6568
log.info("Blocking pop...waiting for message");
66-
StepVerifier.create(blpop) //
69+
blpop.as(StepVerifier::create) //
6770
.then(() -> {
6871

6972
Mono.delay(Duration.ofSeconds(10)).doOnSuccess(it -> {

redis/reactive/src/test/java/example/springdata/redis/operations/ValueOperationsTests.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class ValueOperationsTests {
4646

4747
@BeforeEach
4848
void before() {
49-
StepVerifier.create(operations.execute(it -> it.serverCommands().flushDb())).expectNext("OK").verifyComplete();
49+
50+
operations.execute(it -> it.serverCommands().flushDb()).as(StepVerifier::create) //
51+
.expectNext("OK") //
52+
.verifyComplete();
5053
}
5154

5255
/**
@@ -67,14 +70,14 @@ void shouldCacheValue() {
6770

6871
log.info("Initial access (takes a while...)");
6972

70-
StepVerifier.create(cachedMono).expectSubscription() //
73+
cachedMono.as(StepVerifier::create).expectSubscription() //
7174
.expectNoEvent(Duration.ofSeconds(9)) //
7275
.expectNext("Hello, World!") //
7376
.verifyComplete();
7477

7578
log.info("Subsequent access (use cached value)");
7679

77-
var duration = StepVerifier.create(cachedMono) //
80+
var duration = cachedMono.as(StepVerifier::create) //
7881
.expectNext("Hello, World!") //
7982
.verifyComplete();
8083

0 commit comments

Comments
 (0)