Issue #3536: changed assume into if because of powermock interference

This commit is contained in:
rnveach 2016-11-18 18:52:10 -05:00 committed by Roman Ivanov
parent 19ffe1bb1b
commit 0e8c819d0e
1 changed files with 30 additions and 26 deletions

View File

@ -30,7 +30,6 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@ -229,39 +228,44 @@ public class SuppressionFilterTest extends BaseCheckTestSupport {
}
// Run the test only if connection is available and url is reachable.
Assume.assumeFalse(urlForTest == null);
// We must use an if statement over junit's rule or assume because
// powermock disrupts the assume exception and turns into a failure
// instead of a skip when it doesn't pass
if (urlForTest != null) {
final DefaultConfiguration firstFilterConfig =
createCheckConfig(SuppressionFilter.class);
firstFilterConfig.addAttribute("file", urlForTest);
final DefaultConfiguration firstFilterConfig = createCheckConfig(SuppressionFilter.class);
firstFilterConfig.addAttribute("file", urlForTest);
final DefaultConfiguration firstCheckerConfig =
new DefaultConfiguration("checkstyle_checks");
firstCheckerConfig.addChild(firstFilterConfig);
final String cacheFile = temporaryFolder.newFile().getPath();
firstCheckerConfig.addAttribute("cacheFile", cacheFile);
final DefaultConfiguration firstCheckerConfig =
new DefaultConfiguration("checkstyle_checks");
firstCheckerConfig.addChild(firstFilterConfig);
final String cacheFile = temporaryFolder.newFile().getPath();
firstCheckerConfig.addAttribute("cacheFile", cacheFile);
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(firstCheckerConfig);
checker.addListener(new BriefUtLogger(stream));
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(firstCheckerConfig);
checker.addListener(new BriefUtLogger(stream));
final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, pathToEmptyFile, expected);
verify(checker, pathToEmptyFile, expected);
// One more time to use cache.
final DefaultConfiguration secondFilterConfig =
createCheckConfig(SuppressionFilter.class);
secondFilterConfig.addAttribute("file", urlForTest);
// One more time to use cache.
final DefaultConfiguration secondFilterConfig = createCheckConfig(SuppressionFilter.class);
secondFilterConfig.addAttribute("file", urlForTest);
final DefaultConfiguration secondCheckerConfig =
new DefaultConfiguration("checkstyle_checks");
secondCheckerConfig.addAttribute("cacheFile", cacheFile);
secondCheckerConfig.addChild(secondFilterConfig);
final DefaultConfiguration secondCheckerConfig =
new DefaultConfiguration("checkstyle_checks");
secondCheckerConfig.addAttribute("cacheFile", cacheFile);
secondCheckerConfig.addChild(secondFilterConfig);
checker.configure(secondCheckerConfig);
checker.configure(secondCheckerConfig);
verify(checker, pathToEmptyFile, expected);
verify(checker, pathToEmptyFile, expected);
}
}
private static boolean isConnectionAvailableAndStable(String url) throws Exception {