diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-19 15:29:03 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-19 17:14:45 +0100 |
commit | ad5d5937a83af9377dbf1044f900e967c122c041 (patch) | |
tree | 49ecf915c81e68fc0c3dfa701a6d0954bb62bacc /sonar-batch/src | |
parent | acc1f7b6c754afd765cedd4cd19400ac1c495cea (diff) | |
download | sonarqube-ad5d5937a83af9377dbf1044f900e967c122c041.tar.gz sonarqube-ad5d5937a83af9377dbf1044f900e967c122c041.zip |
Improve stability of unit test coverage
Diffstat (limited to 'sonar-batch/src')
3 files changed, 26 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java index 79a6257a504..e16bfaf4275 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java @@ -26,7 +26,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -35,9 +34,7 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; - import javax.annotation.Nullable; - import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; @@ -135,7 +132,7 @@ public class ServerClient { // SONAR-4397 Details are in response content return new IllegalStateException(tryParseAsJsonError(he.getResponseContent()), he); } - return new IllegalStateException(String.format("Fail to execute request [code=%s, url=%s]", he.getResponseCode(), he.getUri()), he); + return new IllegalStateException(String.format("Fail to execute request [code=%s, url=%s]: %s", he.getResponseCode(), he.getUri(), he.getResponseContent()), he); } private static String tryParseAsJsonError(String responseContent) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java index 45af927e0bd..58079d6b3b8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java @@ -19,25 +19,22 @@ */ package org.sonar.batch.scan.report; -import org.sonar.batch.issue.tracking.TrackedIssue; - import com.google.common.collect.Maps; - import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; - import org.sonar.api.batch.rule.Rule; import org.sonar.api.rules.RulePriority; +import org.sonar.batch.issue.tracking.TrackedIssue; public class ReportSummary { private final IssueVariation total = new IssueVariation(); - private final Map<ReportRuleKey, RuleReport> ruleReportByRuleKey = Maps.newHashMap(); - private final Map<String, IssueVariation> totalByRuleKey = Maps.newHashMap(); - private final Map<String, IssueVariation> totalBySeverity = Maps.newHashMap(); + private final Map<ReportRuleKey, RuleReport> ruleReportByRuleKey = Maps.newLinkedHashMap(); + private final Map<String, IssueVariation> totalByRuleKey = Maps.newLinkedHashMap(); + private final Map<String, IssueVariation> totalBySeverity = Maps.newLinkedHashMap(); public IssueVariation getTotal() { return total; diff --git a/sonar-batch/src/test/java/org/sonar/batch/util/ProgressReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/util/ProgressReportTest.java index dd2d131bf0e..cec84572543 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/util/ProgressReportTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/util/ProgressReportTest.java @@ -20,19 +20,23 @@ package org.sonar.batch.util; import java.util.Set; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.Before; - public class ProgressReportTest { private static final String THREAD_NAME = "progress"; private ProgressReport progressReport; + @Rule + public LogTester logTester = new LogTester(); + @Before public void setUp() { - progressReport = new ProgressReport(THREAD_NAME, 1000); + progressReport = new ProgressReport(THREAD_NAME, 100); } @Test @@ -50,6 +54,19 @@ public class ProgressReportTest { progressReport.stop("stop"); } + @Test + public void do_log() { + progressReport.start("start"); + progressReport.message("Some message"); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + // Ignore + } + progressReport.stop("stop"); + assertThat(logTester.logs()).contains("Some message"); + } + private static boolean isDaemon(String name) { Thread t = getThread(name); return (t != null) && t.isDaemon(); |