Skip to content

Commit 445947d

Browse files
committed
spring-projects#414 - Skip MongoDB ChangeStreams tests if MongoDB cannot be started.
1 parent 44b8d42 commit 445947d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

mongodb/util/src/main/java/example/springdata/mongodb/util/EmbeddedMongo.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.Map;
4242
import java.util.function.Function;
4343

44+
import org.junit.AssumptionViolatedException;
4445
import org.junit.rules.ExternalResource;
4546
import org.slf4j.Logger;
4647
import org.slf4j.LoggerFactory;
@@ -181,13 +182,24 @@ public EmbeddedMongo configure() {
181182
}
182183

183184
@Override
184-
protected void before() throws Throwable {
185-
resource.start();
185+
protected void before() {
186+
187+
try {
188+
resource.start();
189+
} catch (RuntimeException e) {
190+
LOGGER.error("Cannot start MongoDB", e);
191+
throw new AssumptionViolatedException("Cannot start MongoDB. Skipping", e);
192+
}
186193
}
187194

188195
@Override
189196
protected void after() {
190-
resource.stop();
197+
198+
try {
199+
resource.stop();
200+
} catch (RuntimeException e) {
201+
LOGGER.error("Cannot stop MongoDB", e);
202+
}
191203
}
192204

193205
public MongoClient getMongoClient() {

0 commit comments

Comments
 (0)