aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-30 17:58:26 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-07-02 13:46:25 +0200
commita38ab4af8afbef30e6f5399fa3697564ee8e08aa (patch)
treee8cc1f2358094a638bd78568d7ef93fd62e93212 /server
parenta64decf6bb997fc6b6c4dd1eb2023720e32443ef (diff)
downloadsonarqube-a38ab4af8afbef30e6f5399fa3697564ee8e08aa.tar.gz
sonarqube-a38ab4af8afbef30e6f5399fa3697564ee8e08aa.zip
Add isHigherThan method
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/component/ComponentTest.java34
2 files changed, 38 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
index afbefdc4a4f..19208aacef6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
@@ -39,6 +39,10 @@ public interface Component {
public boolean isDeeperThan(Type otherType) {
return this.getDepth() > otherType.getDepth();
}
+
+ public boolean isHigherThan(Type otherType) {
+ return this.getDepth() < otherType.getDepth();
+ }
}
Type getType();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ComponentTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ComponentTest.java
index c6b0d901f0e..f7f8f5f3675 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ComponentTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ComponentTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.server.computation.component.Component.Type.DIRECTORY;
+import static org.sonar.server.computation.component.Component.Type.FILE;
import static org.sonar.server.computation.component.Component.Type.MODULE;
import static org.sonar.server.computation.component.Component.Type.PROJECT;
@@ -51,4 +52,37 @@ public class ComponentTest {
public void MODULE_type_is_deeper_than_PROJECT() throws Exception {
assertThat(Component.Type.MODULE.isDeeperThan(PROJECT)).isTrue();
}
+
+ @Test
+ public void FILE_type_is_higher_than_no_other_types() throws Exception {
+ assertThat(Component.Type.FILE.isHigherThan(DIRECTORY)).isFalse();
+ assertThat(Component.Type.FILE.isHigherThan(MODULE)).isFalse();
+ assertThat(Component.Type.FILE.isHigherThan(PROJECT)).isFalse();
+ }
+
+ @Test
+ public void DIRECTORY_type_is_higher_than_FILE() throws Exception {
+ assertThat(Component.Type.DIRECTORY.isHigherThan(FILE)).isTrue();
+ }
+
+ @Test
+ public void MODULE_type_is_higher_than_FILE_AND_DIRECTORY() throws Exception {
+ assertThat(Component.Type.MODULE.isHigherThan(FILE)).isTrue();
+ assertThat(Component.Type.MODULE.isHigherThan(DIRECTORY)).isTrue();
+ }
+
+ @Test
+ public void PROJECT_type_is_higher_than_all_other_types() throws Exception {
+ assertThat(Component.Type.PROJECT.isHigherThan(FILE)).isTrue();
+ assertThat(Component.Type.PROJECT.isHigherThan(DIRECTORY)).isTrue();
+ assertThat(Component.Type.PROJECT.isHigherThan(MODULE)).isTrue();
+ }
+
+ @Test
+ public void any_type_is_not_higher_than_itself() throws Exception {
+ assertThat(Component.Type.FILE.isHigherThan(FILE)).isFalse();
+ assertThat(Component.Type.DIRECTORY.isHigherThan(DIRECTORY)).isFalse();
+ assertThat(Component.Type.MODULE.isHigherThan(MODULE)).isFalse();
+ assertThat(Component.Type.PROJECT.isHigherThan(PROJECT)).isFalse();
+ }
}