]> source.dussan.org Git - sonarqube.git/commitdiff
Add isHigherThan method
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 30 Jun 2015 15:58:26 +0000 (17:58 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 2 Jul 2015 11:46:25 +0000 (13:46 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
server/sonar-server/src/test/java/org/sonar/server/computation/component/ComponentTest.java

index afbefdc4a4f298665d1a62fbea6d9057422d8972..19208aacef6fcaccd6be67842754210447e2e009 100644 (file)
@@ -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();
index c6b0d901f0e9c1737f0ae9931f5dda7cd17387ca..f7f8f5f3675bce11aa62b37f5b32d5c3cfbf2760 100644 (file)
@@ -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();
+  }
 }