}
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;
import org.junit.Test;
import java.util.Arrays;
+import java.util.Collections;
import static org.fest.assertions.Assertions.assertThat;
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();
+ }
}