aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-05-01 16:46:04 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-05-01 16:46:04 +0200
commit5389dd935f2e9a86623508cd67f0e31207b0195f (patch)
tree3a5f6dfddd538a48d14176a9978a2a0b5bbf96dc /sonar-server
parent43199532816a0fb4d9dac523b6236a62f16d6b1a (diff)
downloadsonarqube-5389dd935f2e9a86623508cd67f0e31207b0195f.tar.gz
sonarqube-5389dd935f2e9a86623508cd67f0e31207b0195f.zip
Fix some quality flaws
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule2/RuleNormalizer.java7
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/QueryOptions.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexMediumTest.java (renamed from sonar-server/src/test/java/org/sonar/server/rule2/RuleSearchMediumTest.java)2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/search/QueryOptionsTest.java68
4 files changed, 72 insertions, 7 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleNormalizer.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleNormalizer.java
index 2a9f04322f4..5c33bd6c0ce 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleNormalizer.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule2/RuleNormalizer.java
@@ -20,8 +20,6 @@
package org.sonar.server.rule2;
import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.rule.RuleKey;
import org.sonar.check.Cardinality;
import org.sonar.core.rule.RuleDto;
@@ -33,9 +31,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
- private static final Logger LOG = LoggerFactory.getLogger(RuleNormalizer.class);
-
- private RuleDao ruleDao;
+ private final RuleDao ruleDao;
public static enum RuleField {
KEY("key"),
@@ -62,6 +58,7 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
return key;
}
+ @Override
public String toString() {
return key;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/search/QueryOptions.java b/sonar-server/src/main/java/org/sonar/server/search/QueryOptions.java
index c4a4f242a89..3f9ad8e2d55 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/QueryOptions.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/QueryOptions.java
@@ -120,7 +120,7 @@ public class QueryOptions {
public QueryOptions filterFieldsToReturn(final Set<String> keep) {
if (fieldsToReturn == null) {
- fieldsToReturn = keep;
+ fieldsToReturn = Sets.newHashSet(keep);
} else {
fieldsToReturn = Sets.filter(fieldsToReturn, new Predicate<String>() {
@Override
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RuleSearchMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexMediumTest.java
index 8f21575bf39..ddf538c3854 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule2/RuleSearchMediumTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexMediumTest.java
@@ -39,7 +39,7 @@ import java.util.Collections;
import static org.fest.assertions.Assertions.assertThat;
-public class RuleSearchMediumTest {
+public class RuleIndexMediumTest {
@ClassRule
public static ServerTester tester = new ServerTester();
diff --git a/sonar-server/src/test/java/org/sonar/server/search/QueryOptionsTest.java b/sonar-server/src/test/java/org/sonar/server/search/QueryOptionsTest.java
new file mode 100644
index 00000000000..350712916a0
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/search/QueryOptionsTest.java
@@ -0,0 +1,68 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.search;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class QueryOptionsTest {
+
+ @Test
+ public void fields_to_return() throws Exception {
+ QueryOptions options = new QueryOptions();
+ assertThat(options.getFieldsToReturn()).isEmpty();
+
+ options.setFieldsToReturn(Arrays.asList("one", "two"));
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "two");
+
+ options.addFieldsToReturn(Arrays.asList("three"));
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "two", "three");
+
+ options.addFieldsToReturn("four");
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "two", "three", "four");
+
+ options.filterFieldsToReturn(Sets.newHashSet("one", "four", "five"));
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "four");
+ }
+
+ @Test
+ public void support_immutable_fields() throws Exception {
+ QueryOptions options = new QueryOptions();
+
+ options.setFieldsToReturn(ImmutableList.of("one", "two"));
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "two");
+
+ options.addFieldsToReturn(ImmutableList.of("three"));
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "two", "three");
+
+ options.addFieldsToReturn("four");
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "two", "three", "four");
+
+ options.filterFieldsToReturn(ImmutableSet.of("one", "four", "five"));
+ assertThat(options.getFieldsToReturn()).containsOnly("one", "four");
+ }
+}