Skip to content

Commit 404fce8

Browse files
committed
Fix MongoDbAvailableRule for assumeTrue()
Currently, the `MongoDbAvailableRule` logs a warning about missed availability of the MongoDb server and returns from the `Statement.evaluate()` making the test not ignored but as passed * Fix the exception handling in the `MongoDbAvailableRule` for the `Statement` to call `Assume.assumeTrue()` instead of the plain logging to mark the test as ignored. This will make a JUnit test report looking correctly and also will let Sonar Cube to report test coverage as adequate **Cherry-pick to `5.5.x`**
1 parent 2200c1d commit 404fce8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/rules/MongoDbAvailableRule.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -18,8 +18,7 @@
1818

1919
import java.util.concurrent.TimeUnit;
2020

21-
import org.apache.commons.logging.Log;
22-
import org.apache.commons.logging.LogFactory;
21+
import org.junit.Assume;
2322
import org.junit.rules.MethodRule;
2423
import org.junit.runners.model.FrameworkMethod;
2524
import org.junit.runners.model.Statement;
@@ -39,11 +38,10 @@
3938
*/
4039
public final class MongoDbAvailableRule implements MethodRule {
4140

42-
private final Log logger = LogFactory.getLog(this.getClass());
43-
4441
@Override
4542
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
4643
return new Statement() {
44+
4745
@Override
4846
public void evaluate() throws Throwable {
4947
MongoDbAvailable mongoAvailable = method.getAnnotation(MongoDbAvailable.class);
@@ -57,9 +55,10 @@ public void evaluate() throws Throwable {
5755
.first();
5856
}
5957
catch (Exception e) {
60-
logger.warn("MongoDb is not available. Skipping the test: " +
61-
target.getClass().getSimpleName() + "." + method.getName() + "()");
62-
return;
58+
Assume.assumeTrue(
59+
"Skipping test due to MongoDb not being available on hosts: " +
60+
settings.getClusterSettings().getHosts() + ":\n" + e,
61+
false);
6362
}
6463
}
6564
base.evaluate();

0 commit comments

Comments
 (0)