aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-13 10:01:13 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-13 10:01:13 +0200
commit27aa656e1f6031e54f004c9f91d7919f3cb79722 (patch)
treea92a1f3787dc33fee29481ede7c998dd486fee0d /sonar-db
parent618a3af602f872b99aaaec3ef7b21510e36b45b0 (diff)
downloadsonarqube-27aa656e1f6031e54f004c9f91d7919f3cb79722.tar.gz
sonarqube-27aa656e1f6031e54f004c9f91d7919f3cb79722.zip
SONAR-7545 use ComponentKeys.MAX_COMPONENT_KEY_LENGTH
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java22
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java2
2 files changed, 9 insertions, 15 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java
index eb628cdf6a0..c352c2471d4 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java
@@ -21,35 +21,31 @@
package org.sonar.db.component;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.core.component.ComponentKeys.MAX_COMPONENT_KEY_LENGTH;
public class ComponentValidator {
- private static final int MAX_NAME_LENGTH = 2000;
- private static final int MAX_KEY_LENGTH = 400;
- private static final int MAX_QUALIFIER_LENGTH = 10;
+ private static final int MAX_COMPONENT_NAME_LENGTH = 2000;
+ private static final int MAX_COMPONENT_QUALIFIER_LENGTH = 10;
private ComponentValidator() {
// prevent instantiation
}
public static String checkComponentName(String name) {
- checkArgument(name.length() <= MAX_NAME_LENGTH, "Component name length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
- name.length(), MAX_NAME_LENGTH, name);
+ checkArgument(name.length() <= MAX_COMPONENT_NAME_LENGTH, "Component name length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
+ name.length(), MAX_COMPONENT_NAME_LENGTH, name);
return name;
}
public static String checkComponentKey(String key) {
- checkArgument(isComponentKeyValid(key), "Component key length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
- key.length(), MAX_KEY_LENGTH, key);
+ checkArgument(key.length() <= MAX_COMPONENT_KEY_LENGTH, "Component key length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
+ key.length(), MAX_COMPONENT_KEY_LENGTH, key);
return key;
}
- public static boolean isComponentKeyValid(String key) {
- return key.length() <= MAX_KEY_LENGTH;
- }
-
public static String checkComponentQualifier(String qualifier) {
- checkArgument(qualifier.length() <= MAX_QUALIFIER_LENGTH, "Component qualifier length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
- qualifier.length(), MAX_QUALIFIER_LENGTH, qualifier);
+ checkArgument(qualifier.length() <= MAX_COMPONENT_QUALIFIER_LENGTH, "Component qualifier length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
+ qualifier.length(), MAX_COMPONENT_QUALIFIER_LENGTH, qualifier);
return qualifier;
}
}
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java
index 8e15e278edb..a88b313d6c7 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java
@@ -51,7 +51,6 @@ public class ComponentValidatorTest {
public void check_key() {
String key = repeat("a", 400);
- assertThat(ComponentValidator.isComponentKeyValid(key)).isTrue();
assertThat(ComponentValidator.checkComponentKey(key)).isEqualTo(key);
}
@@ -61,7 +60,6 @@ public class ComponentValidatorTest {
expectedException.expectMessage("Component key length");
String key = repeat("a", 400 + 1);
- assertThat(ComponentValidator.isComponentKeyValid(key)).isFalse();
ComponentValidator.checkComponentKey(key);
}