Skip to content

Commit bc18b52

Browse files
committed
Polishing.
Reformat code. Suppress warnings in tests. Original pull request: #4541 See #4495
1 parent d46af55 commit bc18b52

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ public Mono<Boolean> collectionExists(String collectionName) {
736736
public <T> Mono<Void> dropCollection(Class<T> entityClass) {
737737
return dropCollection(getCollectionName(entityClass));
738738
}
739+
739740
@Override
740741
public Mono<Void> dropCollection(String collectionName) {
741742

@@ -874,7 +875,7 @@ <T> Mono<Window<T>> doScroll(Query query, Class<?> sourceClass, Class<T> targetC
874875
Assert.notNull(targetClass, "Target type must not be null");
875876

876877
EntityProjection<T, ?> projection = operations.introspectProjection(targetClass, sourceClass);
877-
ProjectingReadCallback<?,T> callback = new ProjectingReadCallback<>(mongoConverter, projection, collectionName);
878+
ProjectingReadCallback<?, T> callback = new ProjectingReadCallback<>(mongoConverter, projection, collectionName);
878879
int limit = query.isLimited() ? query.getLimit() + 1 : Integer.MAX_VALUE;
879880

880881
if (query.hasKeyset()) {
@@ -884,7 +885,8 @@ <T> Mono<Window<T>> doScroll(Query query, Class<?> sourceClass, Class<T> targetC
884885

885886
Mono<List<T>> result = doFind(collectionName, ReactiveCollectionPreparerDelegate.of(query),
886887
keysetPaginationQuery.query(), keysetPaginationQuery.fields(), sourceClass,
887-
new QueryFindPublisherPreparer(query, keysetPaginationQuery.sort(), limit, 0, sourceClass), callback).collectList();
888+
new QueryFindPublisherPreparer(query, keysetPaginationQuery.sort(), limit, 0, sourceClass), callback)
889+
.collectList();
888890

889891
return result.map(it -> ScrollUtils.createWindow(query, it, sourceClass, operations));
890892
}
@@ -2012,8 +2014,8 @@ public <T> Flux<ChangeStreamEvent<T>> changeStream(@Nullable String database, @N
20122014
publisher = options.getCollation().map(Collation::toMongoCollation).map(publisher::collation)
20132015
.orElse(publisher);
20142016
publisher = options.getResumeBsonTimestamp().map(publisher::startAtOperationTime).orElse(publisher);
2015-
2016-
if(options.getFullDocumentBeforeChangeLookup().isPresent()) {
2017+
2018+
if (options.getFullDocumentBeforeChangeLookup().isPresent()) {
20172019
publisher = publisher.fullDocumentBeforeChange(options.getFullDocumentBeforeChangeLookup().get());
20182020
}
20192021
return publisher.fullDocument(options.getFullDocumentLookup().orElse(fullDocument));
@@ -2622,7 +2624,7 @@ private WriteConcern potentiallyForceAcknowledgedWrite(@Nullable WriteConcern wc
26222624

26232625
if (ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)) {
26242626
if (wc == null || wc.getWObject() == null
2625-
|| (wc.getWObject() instanceof Number concern && concern.intValue() < 1)) {
2627+
|| (wc.getWObject()instanceof Number concern && concern.intValue() < 1)) {
26262628
return WriteConcern.ACKNOWLEDGED;
26272629
}
26282630
}
@@ -3200,8 +3202,7 @@ public FindPublisher<Document> prepare(FindPublisher<Document> findPublisher) {
32003202

32013203
HintFunction hintFunction = HintFunction.from(query.getHint());
32023204
Meta meta = query.getMeta();
3203-
if (skip <= 0 && limit <= 0 && ObjectUtils.isEmpty(sortObject) && hintFunction.isEmpty()
3204-
&& !meta.hasValues()) {
3205+
if (skip <= 0 && limit <= 0 && ObjectUtils.isEmpty(sortObject) && hintFunction.isEmpty() && !meta.hasValues()) {
32053206
return findPublisherToUse;
32063207
}
32073208

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/messaging/ChangeStreamTask.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ protected MongoCursor<ChangeStreamDocument<Document>> initCursor(MongoTemplate t
9191
BsonTimestamp startAt = null;
9292
boolean resumeAfter = true;
9393

94-
if (options instanceof ChangeStreamRequest.ChangeStreamRequestOptions changeStreamRequestOptions) {
94+
if (options instanceof ChangeStreamRequest.ChangeStreamRequestOptions requestOptions) {
9595

96-
ChangeStreamOptions changeStreamOptions = changeStreamRequestOptions.getChangeStreamOptions();
96+
ChangeStreamOptions changeStreamOptions = requestOptions.getChangeStreamOptions();
9797
filter = prepareFilter(template, changeStreamOptions);
9898

9999
if (changeStreamOptions.getFilter().isPresent()) {
@@ -115,9 +115,7 @@ protected MongoCursor<ChangeStreamDocument<Document>> initCursor(MongoTemplate t
115115
.orElseGet(() -> ClassUtils.isAssignable(Document.class, targetType) ? FullDocument.DEFAULT
116116
: FullDocument.UPDATE_LOOKUP);
117117

118-
if(changeStreamOptions.getFullDocumentBeforeChangeLookup().isPresent()) {
119-
fullDocumentBeforeChange = changeStreamOptions.getFullDocumentBeforeChangeLookup().get();
120-
}
118+
fullDocumentBeforeChange = changeStreamOptions.getFullDocumentBeforeChangeLookup().orElse(null);
121119

122120
startAt = changeStreamOptions.getResumeBsonTimestamp().orElse(null);
123121
}
@@ -158,7 +156,7 @@ protected MongoCursor<ChangeStreamDocument<Document>> initCursor(MongoTemplate t
158156
}
159157

160158
iterable = iterable.fullDocument(fullDocument);
161-
if(fullDocumentBeforeChange != null) {
159+
if (fullDocumentBeforeChange != null) {
162160
iterable = iterable.fullDocumentBeforeChange(fullDocumentBeforeChange);
163161
}
164162

@@ -180,7 +178,8 @@ List<Document> prepareFilter(MongoTemplate template, ChangeStreamOptions options
180178
template.getConverter().getMappingContext(), queryMapper)
181179
: Aggregation.DEFAULT_CONTEXT;
182180

183-
return aggregation.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", denylist));
181+
return aggregation
182+
.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", denylist));
184183
}
185184

186185
if (filter instanceof List) {

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateUnitTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import lombok.AllArgsConstructor;
2424
import lombok.Data;
2525
import lombok.NoArgsConstructor;
26-
import org.springframework.data.mongodb.util.BsonUtils;
2726
import reactor.core.publisher.Flux;
2827
import reactor.core.publisher.Mono;
2928
import reactor.test.StepVerifier;
@@ -93,6 +92,7 @@
9392
import org.springframework.data.mongodb.core.query.Query;
9493
import org.springframework.data.mongodb.core.query.Update;
9594
import org.springframework.data.mongodb.core.timeseries.Granularity;
95+
import org.springframework.data.mongodb.util.BsonUtils;
9696
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
9797
import org.springframework.lang.Nullable;
9898
import org.springframework.test.util.ReflectionTestUtils;
@@ -101,7 +101,6 @@
101101
import com.mongodb.MongoClientSettings;
102102
import com.mongodb.ReadConcern;
103103
import com.mongodb.ReadPreference;
104-
import com.mongodb.WriteConcern;
105104
import com.mongodb.client.model.CountOptions;
106105
import com.mongodb.client.model.CreateCollectionOptions;
107106
import com.mongodb.client.model.DeleteOptions;
@@ -369,7 +368,8 @@ void updateUsesHintStringFromQuery() {
369368
@Test // GH-3218
370369
void updateUsesHintDocumentFromQuery() {
371370

372-
template.updateFirst(new Query().withHint("{ firstname : 1 }"), new Update().set("spring", "data"), Person.class).subscribe();
371+
template.updateFirst(new Query().withHint("{ firstname : 1 }"), new Update().set("spring", "data"), Person.class)
372+
.subscribe();
373373

374374
ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
375375
verify(collection).updateOne(any(Bson.class), any(Bson.class), options.capture());
@@ -1617,11 +1617,11 @@ void changeStreamOptionFullDocumentBeforeChangeShouldBeApplied() {
16171617
when(changeStreamPublisher.fullDocument(any())).thenReturn(changeStreamPublisher);
16181618
when(changeStreamPublisher.fullDocumentBeforeChange(any())).thenReturn(changeStreamPublisher);
16191619

1620-
template
1621-
.changeStream("database", "collection", ChangeStreamOptions.builder().fullDocumentBeforeChangeLookup(FullDocumentBeforeChange.REQUIRED).build(), Object.class)
1622-
.subscribe();
1620+
ChangeStreamOptions options = ChangeStreamOptions.builder()
1621+
.fullDocumentBeforeChangeLookup(FullDocumentBeforeChange.REQUIRED).build();
1622+
template.changeStream("database", "collection", options, Object.class).subscribe();
16231623

1624-
verify(changeStreamPublisher).fullDocumentBeforeChange(eq(FullDocumentBeforeChange.REQUIRED));
1624+
verify(changeStreamPublisher).fullDocumentBeforeChange(FullDocumentBeforeChange.REQUIRED);
16251625

16261626
}
16271627

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/messaging/ChangeStreamTaskUnitTests.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@
4141
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
4242

4343
/**
44+
* Unit tests for {@link ChangeStreamTask}.
45+
*
4446
* @author Christoph Strobl
4547
* @author Myroslav Kosinskyi
4648
*/
4749
@ExtendWith(MockitoExtension.class)
50+
@SuppressWarnings({ "unchecked", "rawtypes" })
4851
class ChangeStreamTaskUnitTests {
4952

50-
ChangeStreamTask task;
5153
@Mock MongoTemplate template;
5254
@Mock MongoDatabase mongoDatabase;
5355
@Mock MongoCollection<Document> mongoCollection;
5456
@Mock ChangeStreamIterable<Document> changeStreamIterable;
55-
private MongoConverter converter;
57+
58+
MongoConverter converter;
5659

5760
@BeforeEach
5861
void setUp() {
@@ -64,9 +67,7 @@ void setUp() {
6467
when(template.getDb()).thenReturn(mongoDatabase);
6568

6669
when(mongoDatabase.getCollection(any())).thenReturn(mongoCollection);
67-
6870
when(mongoCollection.watch(eq(Document.class))).thenReturn(changeStreamIterable);
69-
7071
when(changeStreamIterable.fullDocument(any())).thenReturn(changeStreamIterable);
7172
}
7273

@@ -84,7 +85,7 @@ void shouldNotBreakLovelaceBehavior() {
8485

8586
initTask(request, Document.class);
8687

87-
verify(changeStreamIterable).resumeAfter(eq(resumeToken));
88+
verify(changeStreamIterable).resumeAfter(resumeToken);
8889
}
8990

9091
@Test // DATAMONGO-2258
@@ -102,7 +103,7 @@ void shouldApplyResumeAfterToChangeStream() {
102103

103104
initTask(request, Document.class);
104105

105-
verify(changeStreamIterable).resumeAfter(eq(resumeToken));
106+
verify(changeStreamIterable).resumeAfter(resumeToken);
106107
}
107108

108109
@Test // DATAMONGO-2258
@@ -120,7 +121,7 @@ void shouldApplyStartAfterToChangeStream() {
120121

121122
initTask(request, Document.class);
122123

123-
verify(changeStreamIterable).startAfter(eq(resumeToken));
124+
verify(changeStreamIterable).startAfter(resumeToken);
124125
}
125126

126127
@Test // GH-4495
@@ -136,7 +137,7 @@ void shouldApplyFullDocumentBeforeChangeToChangeStream() {
136137

137138
initTask(request, Document.class);
138139

139-
verify(changeStreamIterable).fullDocumentBeforeChange(eq(FullDocumentBeforeChange.REQUIRED));
140+
verify(changeStreamIterable).fullDocumentBeforeChange(FullDocumentBeforeChange.REQUIRED);
140141
}
141142

142143
private MongoCursor<ChangeStreamDocument<Document>> initTask(ChangeStreamRequest request, Class<?> targetType) {

0 commit comments

Comments
 (0)