]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 16 Dec 2013 17:01:25 +0000 (18:01 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 16 Dec 2013 17:01:25 +0000 (18:01 +0100)
sonar-server/src/main/java/org/sonar/server/qualityprofile/NewProfileQuery.java [deleted file]
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
sonar-server/src/main/java/org/sonar/server/util/RubyUtils.java
sonar-server/src/test/java/org/sonar/server/exceptions/BadRequestExceptionTest.java [new file with mode: 0644]

diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/NewProfileQuery.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/NewProfileQuery.java
deleted file mode 100644 (file)
index 6fdafcb..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.qualityprofile;
-
-public class NewProfileQuery {
-}
index 39e85844dc04634d63e1bfe8e6e6414459383874..4b750c8fc309faa5f496ddeae5f443432ba267a3 100644 (file)
@@ -240,7 +240,7 @@ public class QProfileOperations implements ServerComponent {
 
   private QualityProfileDto findNotNull(Integer id) {
     QualityProfileDto qualityProfile = find(id);
-    return checkNotNull((qualityProfile));
+    return checkNotNull(qualityProfile);
   }
 
   private QualityProfileDto findNotNull(String name, String language) {
index d77243188d5859c33d3b37b852313ed42a7ef3f3..5be37a258f8f4f8690c1f38c3fe47b860529be0c 100644 (file)
@@ -30,7 +30,6 @@ import javax.annotation.Nullable;
 
 import java.util.Date;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @since 3.6
@@ -54,19 +53,6 @@ public class RubyUtils {
     return result;
   }
 
-  public static Map<String, Object> toMap(@Nullable Object o) {
-    Map<String, Object> result = null;
-    if (o != null) {
-      if (o instanceof Map) {
-        // assume that it contains only strings
-        result = (Map) o;
-      } else {
-        throw new IllegalArgumentException("Unsupported type for map: " + o.getClass());
-      }
-    }
-    return result;
-  }
-
   @CheckForNull
   public static Integer toInteger(@Nullable Object o) {
     if (o == null) {
diff --git a/sonar-server/src/test/java/org/sonar/server/exceptions/BadRequestExceptionTest.java b/sonar-server/src/test/java/org/sonar/server/exceptions/BadRequestExceptionTest.java
new file mode 100644 (file)
index 0000000..770d9d3
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.exceptions;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class BadRequestExceptionTest {
+
+  @Test
+  public void test_message() throws Exception {
+    BadRequestException exception = BadRequestException.of("error");
+    assertThat(exception.getMessage()).isEqualTo("error");
+  }
+
+  @Test
+  public void test_l10n_errors() throws Exception {
+    BadRequestException exception = BadRequestException.ofL10n("issue.error.123", "10");
+    assertThat(exception.getMessage()).isNull();
+    assertThat(exception.l10nKey()).isEqualTo("issue.error.123");
+    assertThat(exception.l10nParams()).containsOnly("10");
+  }
+
+  @Test
+  public void test_text_error_message() throws Exception {
+    BadRequestException exception = BadRequestException.of("error");
+    exception.addError("new error");
+
+    assertThat(exception.errors()).hasSize(1);
+    assertThat(exception.errors().get(0).text()).isEqualTo("new error");
+  }
+
+  @Test
+  public void test_l10n_message() throws Exception {
+    BadRequestException.Message msg = BadRequestException.Message.ofL10n("error.123", "10");
+    BadRequestException.Message sameMsg = BadRequestException.Message.ofL10n("error.123", "10");
+    BadRequestException.Message msg2 = BadRequestException.Message.ofL10n("error.123", "200");
+    BadRequestException.Message msg3 = BadRequestException.Message.ofL10n("error.50");
+
+    assertThat(msg.toString()).contains("error.123").contains("10");
+    assertThat(msg).isEqualTo(msg);
+    assertThat(msg).isEqualTo(sameMsg);
+    assertThat(msg.hashCode()).isEqualTo(msg.hashCode());
+    assertThat(msg.hashCode()).isEqualTo(sameMsg.hashCode());
+
+    assertThat(msg).isNotEqualTo(msg2);
+    assertThat(msg).isNotEqualTo(msg3);
+    assertThat(msg).isNotEqualTo("issue.error.123");
+  }
+
+}