From ad5d5937a83af9377dbf1044f900e967c122c041 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 19 Nov 2015 15:29:03 +0100 Subject: Improve stability of unit test coverage --- .../org/sonar/batch/bootstrap/ServerClient.java | 5 +---- .../org/sonar/batch/scan/report/ReportSummary.java | 11 ++++------ .../org/sonar/batch/util/ProgressReportTest.java | 25 ++++++++++++++++++---- 3 files changed, 26 insertions(+), 15 deletions(-) (limited to 'sonar-batch/src') 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 ruleReportByRuleKey = Maps.newHashMap(); - private final Map totalByRuleKey = Maps.newHashMap(); - private final Map totalBySeverity = Maps.newHashMap(); + private final Map ruleReportByRuleKey = Maps.newLinkedHashMap(); + private final Map totalByRuleKey = Maps.newLinkedHashMap(); + private final Map 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(); -- cgit v1.2.3