diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-15 12:54:21 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-15 14:33:21 +0100 |
commit | cdc1c25040fccdf84b46250fa5ad84bb1dde252a (patch) | |
tree | d9ed64a5d0ccded96e8e31a008d61b0210add1c0 /server/sonar-server/src | |
parent | a23cea9726fdcbfb4348a9c2335ae82ecab85c79 (diff) | |
download | sonarqube-cdc1c25040fccdf84b46250fa5ad84bb1dde252a.tar.gz sonarqube-cdc1c25040fccdf84b46250fa5ad84bb1dde252a.zip |
SONAR-8647 Correctly detect isFavorite in filter
Diffstat (limited to 'server/sonar-server/src')
3 files changed, 17 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java index 54b610e6453..0be862b3473 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java @@ -51,10 +51,11 @@ class ProjectMeasuresQueryFactory { return StreamSupport.stream(CRITERIA_SPLITTER.split(filter).spliterator(), false) .filter(Objects::nonNull) .filter(criterion -> !criterion.isEmpty()) + .map(String::trim) .collect(Collectors.toList()); } - static boolean hasIsFavouriteCriterion(List<String> criteria) { + static boolean hasIsFavoriteCriterion(List<String> criteria) { return criteria.stream().anyMatch(IS_FAVORITE_CRITERION::equalsIgnoreCase); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 8785138925a..ab18e47eca5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -60,7 +60,7 @@ import org.sonarqube.ws.client.component.SearchProjectsRequest; import static com.google.common.base.MoreObjects.firstNonNull; import static java.lang.String.format; import static org.sonar.core.util.stream.Collectors.toSet; -import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.hasIsFavouriteCriterion; +import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.hasIsFavoriteCriterion; import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery; import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.toCriteria; import static org.sonar.server.measure.index.ProjectMeasuresIndex.SUPPORTED_FACETS; @@ -193,7 +193,7 @@ public class SearchProjectsAction implements ComponentsWsAction { @CheckForNull private Set<String> buildFilterOnFavoriteProjectUuids(List<String> criteria, Set<String> favoriteProjectUuids) { - if (hasIsFavouriteCriterion(criteria)) { + if (hasIsFavoriteCriterion(criteria)) { return favoriteProjectUuids; } return null; diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java index 80679803f8e..582d23acb2c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java @@ -218,4 +218,17 @@ public class ProjectMeasuresQueryFactoryTest { expectedException.expectMessage("Invalid criterion 'ncloc >='"); newProjectMeasuresQuery(toCriteria("ncloc >="), emptySet()); } + + @Test + public void test_hasIsFavouriteCriterion() throws Exception { + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("isFavorite"))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("isFavorite "))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria(" isFavorite "))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("isFavorite and reliability_rating = 1"))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria(" isFavorite and reliability_rating = 1"))).isTrue(); + + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("ncloc > 10"))).isFalse(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("ncloc > 10 and coverage <= 80"))).isFalse(); + } + } |