]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 14 Dec 2016 17:18:23 +0000 (18:18 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 14 Dec 2016 17:23:28 +0000 (18:23 +0100)
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/EventValidator.java
server/sonar-server/src/main/java/org/sonar/server/setting/ws/ResetAction.java
server/sonar-server/src/main/java/org/sonar/server/setting/ws/SetAction.java
server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingValidations.java
sonar-ws/src/main/java/org/sonarqube/ws/client/license/package-info.java [new file with mode: 0644]
sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequestTest.java

index 52604c00cb6abe703d4aaf5fbc0792c00f7db762..480fd627c66e7827419a6389fb8aaa067568a715 100644 (file)
@@ -32,6 +32,10 @@ class EventValidator {
   private static final Set<String> AUTHORIZED_CATEGORIES = ImmutableSet.of("Version", "Other");
   private static final String AUTHORIZED_CATEGORIES_INLINED = Joiner.on(", ").join(AUTHORIZED_CATEGORIES);
 
+  private EventValidator() {
+    // prevent instantiation
+  }
+
   static Consumer<EventDto> checkModifiable() {
     return event -> checkArgument(AUTHORIZED_CATEGORIES.contains(event.getCategory()),
       "Event of category '%s' cannot be modified. Authorized categories: %s",
index baea3587c534da9785ea0996fd464f2a0410247e..482c5ee554dc24a11af619101b1fd202e9889570 100644 (file)
@@ -98,7 +98,7 @@ public class ResetAction implements SettingsWsAction {
       resetRequest.getKeys().forEach(key -> {
         SettingData data = new SettingData(key, emptyList(), component.orElse(null));
         ImmutableList.of(validations.scope(), validations.qualifier())
-          .forEach(validation -> validation.validate(data));
+          .forEach(validation -> validation.accept(data));
       });
 
       List<String> keys = getKeys(resetRequest);
index 38fbb074e17628859f18419292dfedb075d54b82..7036a0572f125977361d8924cd2bf5415466047a 100644 (file)
@@ -206,10 +206,10 @@ public class SetAction implements SettingsWsAction {
     checkValueIsSet(request);
     SettingData settingData = new SettingData(request.getKey(), valuesFromRequest(request), component.orElse(null));
     ImmutableList.of(validations.scope(), validations.qualifier(), validations.valueType())
-      .forEach(validation -> validation.validate(settingData));
+      .forEach(validation -> validation.accept(settingData));
   }
 
-  private void validatePropertySet(SetRequest request, @Nullable PropertyDefinition definition) {
+  private static void validatePropertySet(SetRequest request, @Nullable PropertyDefinition definition) {
     checkRequest(definition != null, "Setting '%s' is undefined", request.getKey());
     checkRequest(PropertyType.PROPERTY_SET.equals(definition.type()), "Parameter '%s' is used for setting of property set type only", PARAM_FIELD_VALUES);
 
index 89291bbc97b2cb7e2a14e19ac616d59910ea461e..c5b905d8b026408872158013c650ed683942eaeb 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.setting.ws;
 
 import java.util.List;
 import java.util.Locale;
+import java.util.function.Consumer;
 import java.util.stream.Collectors;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
@@ -51,7 +52,7 @@ public class SettingValidations {
     this.i18n = i18n;
   }
 
-  public SettingValidation scope() {
+  public Consumer<SettingData> scope() {
     return data -> {
       PropertyDefinition definition = definitions.get(data.key);
       checkRequest(data.component != null || definition == null || definition.global() || isGlobal(definition),
@@ -59,7 +60,7 @@ public class SettingValidations {
     };
   }
 
-  public SettingValidation qualifier() {
+  public Consumer<SettingData> qualifier() {
     return data -> {
       String qualifier = data.component == null ? "" : data.component.qualifier();
       PropertyDefinition definition = definitions.get(data.key);
@@ -68,7 +69,7 @@ public class SettingValidations {
     };
   }
 
-  public SettingValidation valueType() {
+  public Consumer<SettingData> valueType() {
     return new ValueTypeValidation();
   }
 
@@ -76,11 +77,6 @@ public class SettingValidations {
     return !definition.global() && definition.qualifiers().isEmpty();
   }
 
-  @FunctionalInterface
-  public interface SettingValidation {
-    void validate(SettingData data);
-  }
-
   public static class SettingData {
     private final String key;
     private final List<String> values;
@@ -94,10 +90,9 @@ public class SettingValidations {
     }
   }
 
-  private class ValueTypeValidation implements SettingValidation {
-
+  private class ValueTypeValidation implements Consumer<SettingData> {
     @Override
-    public void validate(SettingData data) {
+    public void accept(SettingData data) {
       PropertyDefinition definition = definitions.get(data.key);
       if (definition == null) {
         return;
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/license/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/package-info.java
new file mode 100644 (file)
index 0000000..9b7cf2a
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.license;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index 75586393422bf9e7a491ddef8b69fba86820091b..1d07f29b1cefaad49f2ea08a2525d97a57a9a943 100644 (file)
@@ -49,7 +49,7 @@ public class CreateEventRequestTest {
   public void other_category_by_default() {
     CreateEventRequest result = underTest.setAnalysis("P1").setName("name").build();
 
-    assertThat(OTHER.equals(result.getCategory()));
+    assertThat(OTHER).isEqualTo(result.getCategory());
   }
 
   @Test