Fix Sonar issues in deprecated RepeatProcessor

This commit is contained in:
Gary Russell
2019-08-23 09:11:33 -04:00
parent 868979d9a4
commit 1fed5a7443

View File

@@ -34,7 +34,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.internal.runners.statements.RunAfters;
import org.junit.internal.runners.statements.RunBefores;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
@@ -47,7 +46,7 @@ import org.springframework.test.annotation.Repeat;
* A JUnit method @Rule that looks at Spring repeat annotations on methods and executes the test multiple times
* (without re-initializing the test case if necessary). To avoid re-initializing use the {@link #isInitialized()}
* method to protect the @Before and @After methods.
* @deprecated in favor of JUnit 5 {@link RepeatedTest}.
* @deprecated in favor of JUnit 5 {@link org.junit.jupiter.api.RepeatedTest}.
*
* @author Dave Syer
*
@@ -55,7 +54,7 @@ import org.springframework.test.annotation.Repeat;
@Deprecated
public class RepeatProcessor implements MethodRule {
private static final Log logger = LogFactory.getLog(RepeatProcessor.class);
private static final Log LOGGER = LogFactory.getLog(RepeatProcessor.class);
private final int concurrency;
@@ -95,7 +94,7 @@ public class RepeatProcessor implements MethodRule {
try {
base.evaluate();
}
catch (Throwable t) {
catch (Throwable t) { // NOSONAR
throw new IllegalStateException(
"Failed on iteration: " + i + " of " + repeats + " (started at 0)", t);
}
@@ -107,7 +106,7 @@ public class RepeatProcessor implements MethodRule {
}
};
}
return new Statement() {
return new Statement() { // NOSONAR
@Override
public void evaluate() throws Throwable {
List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
@@ -122,7 +121,7 @@ public class RepeatProcessor implements MethodRule {
try {
base.evaluate();
}
catch (Throwable t) {
catch (Throwable t) { // NOSONAR
throw new IllegalStateException("Failed on iteration: " + count, t);
}
return true;
@@ -147,7 +146,7 @@ public class RepeatProcessor implements MethodRule {
List<FrameworkMethod> afters = new TestClass(target.getClass()).getAnnotatedMethods(After.class);
try {
if (!afters.isEmpty()) {
logger.debug("Running @After methods");
LOGGER.debug("Running @After methods");
try {
new RunAfters(new Statement() {
@Override
@@ -155,7 +154,7 @@ public class RepeatProcessor implements MethodRule {
}
}, afters, target).evaluate();
}
catch (Throwable e) {
catch (Throwable e) { // NOSONAR
fail("Unexpected throwable " + e);
}
}
@@ -169,7 +168,7 @@ public class RepeatProcessor implements MethodRule {
TestClass testClass = new TestClass(target.getClass());
List<FrameworkMethod> befores = testClass.getAnnotatedMethods(Before.class);
if (!befores.isEmpty()) {
logger.debug("Running @Before methods");
LOGGER.debug("Running @Before methods");
try {
new RunBefores(new Statement() {
@Override
@@ -177,7 +176,7 @@ public class RepeatProcessor implements MethodRule {
}
}, befores, target).evaluate();
}
catch (Throwable e) {
catch (Throwable e) { // NOSONAR
fail("Unexpected throwable " + e);
}
this.initialized = true;