From: Julien Lancelot Date: Thu, 18 Jul 2013 16:17:44 +0000 (+0200) Subject: Restore BadRequestException when action is not found X-Git-Tag: 3.7~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4bdf4fea4c183147b9dc50436232d6e8a87d07c5;p=sonarqube.git Restore BadRequestException when action is not found --- diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java index 55cf6efb5e1..dc9253a3910 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java @@ -32,6 +32,7 @@ import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.web.UserRole; import org.sonar.core.issue.IssueNotifications; import org.sonar.core.issue.db.IssueStorage; +import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.user.UserSession; import java.util.Date; @@ -110,12 +111,16 @@ public class IssueBulkChangeService { } private Action getAction(final String actionKey) { - return Iterables.find(actions, new Predicate() { + Action action = Iterables.find(actions, new Predicate() { @Override public boolean apply(Action action) { return action.key().equals(actionKey); } - }); + }, null); + if (action == null) { + throw new BadRequestException("The action : '"+ actionKey + "' is unknown"); + } + return action; } static class ActionContext implements Action.Context { diff --git a/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java b/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java index 6a9ac61b342..70281632224 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java @@ -32,13 +32,13 @@ import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.web.UserRole; import org.sonar.core.issue.IssueNotifications; import org.sonar.core.issue.db.IssueStorage; +import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.user.MockUserSession; import org.sonar.server.user.UserSession; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Maps.newHashMap; @@ -277,7 +277,7 @@ public class IssueBulkChangeServiceTest { service.execute(issueBulkChangeQuery, userSession); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(NoSuchElementException.class); + assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("The action : 'unknown' is unknown"); } verifyZeroInteractions(issueStorage); verifyZeroInteractions(issueNotifications);