diff options
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(); + } } |