From 483c5adb3c941540ba9956cb998c5f39fb856786 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 10 Dec 2012 16:39:28 +0100 Subject: [PATCH] SONAR-3825 do not force to set qualifiers when "Favourites only" is set --- .../org/sonar/core/measure/MeasureFilter.java | 6 ++-- .../sonar/core/measure/MeasureFilterTest.java | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java index 3b88f5528bf..e5c64d2d6a0 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java @@ -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 sanitize(@Nullable List list) { - return isBlank(list) ? Collections.emptyList() : Lists.newArrayList(list); + return isEmptyList(list) ? Collections.emptyList() : Lists.newArrayList(list); } - private static boolean isBlank(@Nullable List list) { + private static boolean isEmptyList(@Nullable List list) { boolean blank = false; if (list == null || list.isEmpty() || (list.size() == 1 && Strings.isNullOrEmpty(list.get(0)))) { blank = true; diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterTest.java index 74f30fa727e..ac2130f409e 100644 --- a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterTest.java +++ b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterTest.java @@ -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.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.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(); + } } -- 2.39.5