]> source.dussan.org Git - sonarqube.git/commitdiff
Restore BadRequestException when action is not found
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 18 Jul 2013 16:17:44 +0000 (18:17 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 18 Jul 2013 16:20:58 +0000 (18:20 +0200)
sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java
sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java

index 55cf6efb5e1e13631df1a9c56773edc7de19bad9..dc9253a3910b14eaa9f8e9ce5eda44c72d6d1dab 100644 (file)
@@ -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 action = Iterables.find(actions, new Predicate<Action>() {
       @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 {
index 6a9ac61b342216f7e9ef689057950e61d68dabd6..702816322240f7174dc2577213c369fa8cc41ecd 100644 (file)
@@ -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);