]> source.dussan.org Git - sonarqube.git/commitdiff
Added assertion in DeleteKey action
authorStephane Gamard <stephane.gamard@sonarsource.com>
Wed, 8 Oct 2014 07:45:53 +0000 (09:45 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Wed, 8 Oct 2014 07:45:53 +0000 (09:45 +0200)
server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java
server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java

index 517fb74cd3f6b32b1b8304bad11a0ba41c8d8ce9..830e1b6cc8b330424a25782386bffe9db82fa7f9 100644 (file)
@@ -27,6 +27,8 @@ import java.util.List;
 
 public abstract class IndexAction<K extends ActionRequest> implements ClusterAction<List<K>> {
 
+  public static final String MISSING_INDEX_EXCEPTION = "Cannot execute request on null index";
+
   protected final String indexType;
   private final boolean requiresRefresh;
   private Index index;
@@ -54,7 +56,7 @@ public abstract class IndexAction<K extends ActionRequest> implements ClusterAct
   @Override
   public final List<K> call() throws Exception {
     if (index == null) {
-      throw new IllegalStateException("Cannot execute request on null index");
+      throw new IllegalStateException(MISSING_INDEX_EXCEPTION);
     }
     return doCall(index);
   }
index 375e800bf451807e68873eced226ead2586b9d57..5798b0da109dff50aab65d9b1a1a54e0f2da0963 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.server.search.IndexDefinition;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -48,7 +49,17 @@ public class DeleteKeyTest {
     String key = "test_key";
     DeleteKey<String> deleteAction = new DeleteKey<String>(TEST_INDEX.getIndexType(), key);
 
-    List<DeleteRequest> requests = deleteAction.doCall(index);
+    try {
+      deleteAction.call();
+      fail();
+    } catch (Exception e) {
+      assertThat(e.getMessage()).isEqualTo(IndexAction.MISSING_INDEX_EXCEPTION);
+    }
+
+    // Insert Index for action
+    deleteAction.setIndex(index);
+
+    List<DeleteRequest> requests = deleteAction.call();
     assertThat(requests).hasSize(1);
 
     DeleteRequest request = requests.get(0);