From d3a51c25cb09f85ce0bfe636787931229c0d3bb9 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Wed, 8 Oct 2014 09:45:53 +0200 Subject: [PATCH] Added assertion in DeleteKey action --- .../org/sonar/server/search/action/IndexAction.java | 4 +++- .../sonar/server/search/action/DeleteKeyTest.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java index 517fb74cd3f..830e1b6cc8b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java @@ -27,6 +27,8 @@ import java.util.List; public abstract class IndexAction implements ClusterAction> { + 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 implements ClusterAct @Override public final List call() throws Exception { if (index == null) { - throw new IllegalStateException("Cannot execute request on null index"); + throw new IllegalStateException(MISSING_INDEX_EXCEPTION); } return doCall(index); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java index 375e800bf45..5798b0da109 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java @@ -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 deleteAction = new DeleteKey(TEST_INDEX.getIndexType(), key); - List 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 requests = deleteAction.call(); assertThat(requests).hasSize(1); DeleteRequest request = requests.get(0); -- 2.39.5