]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 do not force to set qualifiers when "Favourites only" is set
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 10 Dec 2012 15:39:28 +0000 (16:39 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 10 Dec 2012 17:22:24 +0000 (18:22 +0100)
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java
sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterTest.java

index 3b88f5528bf5687570174f07427462a454983915..e5c64d2d6a0c54ba61a4c374319ef060e64bdbd8 100644 (file)
@@ -196,15 +196,15 @@ public class MeasureFilter {
   }
 
   public boolean isEmpty() {
-    return resourceQualifiers.isEmpty() && resourceScopes.isEmpty() && StringUtils.isEmpty(baseResourceKey) && baseResourceId==null;
+    return resourceQualifiers.isEmpty() && resourceScopes.isEmpty() && StringUtils.isEmpty(baseResourceKey) && baseResourceId==null && !userFavourites;
   }
 
   @VisibleForTesting
   static List<String> sanitize(@Nullable List<String> list) {
-    return isBlank(list) ? Collections.<String>emptyList() : Lists.newArrayList(list);
+    return isEmptyList(list) ? Collections.<String>emptyList() : Lists.newArrayList(list);
   }
 
-  private static boolean isBlank(@Nullable List<String> list) {
+  private static boolean isEmptyList(@Nullable List<String> list) {
     boolean blank = false;
     if (list == null || list.isEmpty() || (list.size() == 1 && Strings.isNullOrEmpty(list.get(0)))) {
       blank = true;
index 74f30fa727ea5cf418d8868a64219aeff13e359f..ac2130f409edb81aa6d101c90440f58aa6c6919b 100644 (file)
@@ -23,6 +23,7 @@ import com.google.common.collect.Lists;
 import org.junit.Test;
 
 import java.util.Arrays;
+import java.util.Collections;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -35,4 +36,31 @@ public class MeasureFilterTest {
     assertThat(MeasureFilter.sanitize(Lists.newArrayList("TRK"))).containsExactly("TRK");
     assertThat(MeasureFilter.sanitize(Lists.newArrayList("TRK", "BRC"))).containsExactly("TRK", "BRC");
   }
+
+  @Test
+  public void filter_is_not_empty_if_at_least_condition_on_favourites() {
+    assertThat(new MeasureFilter().isEmpty()).isTrue();
+    assertThat(new MeasureFilter().setUserFavourites(true).isEmpty()).isFalse();
+  }
+
+  @Test
+  public void filter_is_not_empty_if_at_least_condition_on_qualifiers() {
+    assertThat(new MeasureFilter().isEmpty()).isTrue();
+    assertThat(new MeasureFilter().setResourceQualifiers(Collections.<String>emptyList()).isEmpty()).isTrue();
+    assertThat(new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).isEmpty()).isFalse();
+  }
+
+  @Test
+  public void filter_is_not_empty_if_at_least_condition_on_scopes() {
+    assertThat(new MeasureFilter().isEmpty()).isTrue();
+    assertThat(new MeasureFilter().setResourceScopes(Collections.<String>emptyList()).isEmpty()).isTrue();
+    assertThat(new MeasureFilter().setResourceScopes(Arrays.asList("PRJ")).isEmpty()).isFalse();
+  }
+
+  @Test
+  public void filter_is_not_empty_if_at_least_condition_on_root_resource() {
+    assertThat(new MeasureFilter().isEmpty()).isTrue();
+    assertThat(new MeasureFilter().setBaseResourceKey("foo").isEmpty()).isFalse();
+    assertThat(new MeasureFilter().setBaseResourceId(123L).isEmpty()).isFalse();
+  }
 }