aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-10 09:25:24 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-14 09:07:59 +0200
commit28d06e64fc9658e8d6b6947d1213a6e046aac2fc (patch)
tree719a10da3f94bdf12fd5b3dd218d04d4e6de8df2
parentae034306558d3483eae35ada281036e53e833317 (diff)
downloadsonarqube-28d06e64fc9658e8d6b6947d1213a6e046aac2fc.tar.gz
sonarqube-28d06e64fc9658e8d6b6947d1213a6e046aac2fc.zip
Fix some quality flaws
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java20
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java2
3 files changed, 19 insertions, 12 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java
index df46490c7af..9118dc3450e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java
@@ -129,11 +129,12 @@ public class DefaultFileLinesContext implements FileLinesContext {
private Map loadData(String metricKey, Converter converter) {
// FIXME no way to load measure only by key
Measure measure = index.getMeasure(resource, new Metric(metricKey));
- if (measure == null || measure.getData() == null) {
- // no such measure
- return ImmutableMap.of();
+ String data = measure != null ? measure.getData() : null;
+ if (data != null) {
+ return ImmutableMap.copyOf(KeyValueFormat.parse(data, KeyValueFormat.newIntegerConverter(), converter));
}
- return ImmutableMap.copyOf(KeyValueFormat.parse(measure.getData(), KeyValueFormat.newIntegerConverter(), converter));
+ // no such measure
+ return ImmutableMap.of();
}
/**
diff --git a/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java
index ea5ac2168d5..57520582d01 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java
@@ -19,11 +19,10 @@
*/
package org.sonar.batch;
-import org.mockito.Matchers;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Matchers;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
@@ -32,10 +31,15 @@ import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
+import static org.fest.assertions.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class DefaultFileLinesContextTest {
@@ -62,6 +66,8 @@ public class DefaultFileLinesContextTest {
fileLineMeasures.setIntValue("hits", 3, 4);
fileLineMeasures.save();
+ assertThat(fileLineMeasures.toString()).isEqualTo("DefaultFileLinesContext{map={hits={1=2, 3=4}}}");
+
ArgumentCaptor<Measure> measureCaptor = ArgumentCaptor.forClass(Measure.class);
verify(index).addMeasure(Matchers.eq(resource), measureCaptor.capture());
Measure measure = measureCaptor.getValue();
@@ -96,7 +102,7 @@ public class DefaultFileLinesContextTest {
@Test
public void shouldLoadIntValues() {
when(index.getMeasure(Matchers.any(Resource.class), Matchers.any(Metric.class)))
- .thenReturn(new Measure("hits").setData("1=2;3=4"));
+ .thenReturn(new Measure("hits").setData("1=2;3=4"));
assertThat(fileLineMeasures.getIntValue("hits", 1), is(2));
assertThat(fileLineMeasures.getIntValue("hits", 3), is(4));
@@ -106,7 +112,7 @@ public class DefaultFileLinesContextTest {
@Test
public void shouldLoadStringValues() {
when(index.getMeasure(Matchers.any(Resource.class), Matchers.any(Metric.class)))
- .thenReturn(new Measure("author").setData("1=simon;3=evgeny"));
+ .thenReturn(new Measure("author").setData("1=simon;3=evgeny"));
assertThat(fileLineMeasures.getStringValue("author", 1), is("simon"));
assertThat(fileLineMeasures.getStringValue("author", 3), is("evgeny"));
@@ -116,7 +122,7 @@ public class DefaultFileLinesContextTest {
@Test
public void shouldNotSaveAfterLoad() {
when(index.getMeasure(Matchers.any(Resource.class), Matchers.any(Metric.class)))
- .thenReturn(new Measure("author").setData("1=simon;3=evgeny"));
+ .thenReturn(new Measure("author").setData("1=simon;3=evgeny"));
fileLineMeasures.getStringValue("author", 1);
fileLineMeasures.save();
@@ -127,7 +133,7 @@ public class DefaultFileLinesContextTest {
@Test(expected = UnsupportedOperationException.class)
public void shouldNotModifyAfterLoad() {
when(index.getMeasure(Matchers.any(Resource.class), Matchers.any(Metric.class)))
- .thenReturn(new Measure("author").setData("1=simon;3=evgeny"));
+ .thenReturn(new Measure("author").setData("1=simon;3=evgeny"));
fileLineMeasures.getStringValue("author", 1);
fileLineMeasures.setStringValue("author", 1, "evgeny");
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
index e7b29cad25f..da6ff4280f8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
@@ -341,7 +341,7 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
private final String responseContent;
public HttpException(URI uri, int responseContent) {
- this(uri, responseContent, null);
+ this(uri, responseContent, "");
}
public HttpException(URI uri, int responseCode, String responseContent) {