aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-09-08 16:57:52 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-09-10 17:06:52 +0200
commitf5188bef88d23d4f48a3999ea41b269474845bde (patch)
tree4e4517efbf4501268f19bb575bea9c2a08bb1b31 /server
parentc32f64c4072222e001a0dffe55ceb776dff7b4ba (diff)
downloadsonarqube-f5188bef88d23d4f48a3999ea41b269474845bde.tar.gz
sonarqube-f5188bef88d23d4f48a3999ea41b269474845bde.zip
SONAR-6827 Add hasCharacteristicById
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolder.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolderImpl.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/debt/DebtModelHolderImplTest.java8
3 files changed, 25 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolder.java
index 0290164b18b..de719f7b9eb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolder.java
@@ -32,5 +32,17 @@ public interface DebtModelHolder {
*/
Characteristic getCharacteristicById(int id);
+ /**
+ * Check if a characteristic exists by its id
+ *
+ * @throws IllegalStateException if the holder is not initialized yet
+ */
+ boolean hasCharacteristicById(int id);
+
+ /**
+ * Return list of root characteristics
+ *
+ * @throws IllegalStateException if the holder is not initialized yet
+ */
List<Characteristic> getRootCharacteristics();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolderImpl.java
index a66b8354271..aae51e58c4d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolderImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/debt/DebtModelHolderImpl.java
@@ -59,6 +59,11 @@ public class DebtModelHolderImpl implements MutableDebtModelHolder {
}
@Override
+ public boolean hasCharacteristicById(int id) {
+ return characteristicById.get(id) != null;
+ }
+
+ @Override
public List<Characteristic> getRootCharacteristics() {
checkInitialized();
return rootCharacteristics;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/debt/DebtModelHolderImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/debt/DebtModelHolderImplTest.java
index 8147505f622..393a7ac7b9e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/debt/DebtModelHolderImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/debt/DebtModelHolderImplTest.java
@@ -99,4 +99,12 @@ public class DebtModelHolderImplTest {
underTest.getRootCharacteristics();
}
+
+ @Test
+ public void has_characteristic() throws Exception {
+ underTest.addCharacteristics(PORTABILITY, Arrays.asList(COMPILER_RELATED_PORTABILITY, READABILITY));
+
+ assertThat(underTest.hasCharacteristicById(PORTABILITY.getId())).isTrue();
+ assertThat(underTest.hasCharacteristicById(123)).isFalse();
+ }
}