Skip to content

Commit a09af7e

Browse files
committed
Merge branch '3.2.x' into 3.3.x
Closes gh-42059
2 parents 71f509c + 1085505 commit a09af7e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/PropertiesMongoConnectionDetails.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -23,6 +23,8 @@
2323

2424
import com.mongodb.ConnectionString;
2525

26+
import org.springframework.util.StringUtils;
27+
2628
/**
2729
* Adapts {@link MongoProperties} to {@link MongoConnectionDetails}.
2830
*
@@ -90,7 +92,7 @@ public GridFs getGridFs() {
9092

9193
private List<String> getOptions() {
9294
List<String> options = new ArrayList<>();
93-
if (this.properties.getReplicaSetName() != null) {
95+
if (StringUtils.hasText(this.properties.getReplicaSetName())) {
9496
options.add("replicaSet=" + this.properties.getReplicaSetName());
9597
}
9698
if (this.properties.getUsername() != null && this.properties.getAuthenticationDatabase() != null) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/PropertiesMongoConnectionDetailsTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -104,6 +104,20 @@ void replicaSetCanBeConfiguredWithDatabase() {
104104
assertThat(connectionString.getRequiredReplicaSetName()).isEqualTo("test");
105105
}
106106

107+
@Test
108+
void replicaSetCanBeNull() {
109+
this.properties.setReplicaSetName(null);
110+
ConnectionString connectionString = getConnectionString();
111+
assertThat(connectionString.getRequiredReplicaSetName()).isNull();
112+
}
113+
114+
@Test
115+
void replicaSetCanBeBlank() {
116+
this.properties.setReplicaSetName("");
117+
ConnectionString connectionString = getConnectionString();
118+
assertThat(connectionString.getRequiredReplicaSetName()).isNull();
119+
}
120+
107121
@Test
108122
void whenAdditionalHostsAreConfiguredThenTheyAreIncludedInHostsOfConnectionString() {
109123
this.properties.setHost("mongo1.example.com");

0 commit comments

Comments
 (0)