summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2014-09-18 13:38:58 -0700
committerTor Norbye <tnorbye@google.com>2014-09-18 13:38:58 -0700
commitb5fb31ef6a38f19404859755dbd2e345215b97bf (patch)
treee8787c45e494dfcc558faf0f75956f8785c39b94 /plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java
parente222a9e1e66670a56e926a6b0f3e10231eeeb1fb (diff)
parente782c57d74000722f9db4c9426317410520670c6 (diff)
downloadidea-b5fb31ef6a38f19404859755dbd2e345215b97bf.tar.gz
Merge remote-tracking branch 'aosp/upstream-master' into merge
Conflicts: .idea/libraries/asm_tools.xml .idea/libraries/bouncy_castle.xml .idea/libraries/builder_model.xml .idea/libraries/commons_compress.xml .idea/libraries/easymock_tools.xml .idea/libraries/freemarker_2_3_20.xml .idea/libraries/guava_tools.xml .idea/libraries/kxml2.xml .idea/libraries/lombok_ast.xml .idea/libraries/mockito.xml .idea/modules.xml .idea/vcs.xml build/scripts/layouts.gant updater/src/com/intellij/updater/Runner.java Change-Id: I8e1c173e00cd76c855b8a98543b0a0edfdd99d12
Diffstat (limited to 'plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java')
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java45
1 files changed, 43 insertions, 2 deletions
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java
index 2ce63ec4814e..47fd152debec 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java
@@ -16,15 +16,21 @@
package com.siyeh.ig;
import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.application.PluginPathManager;
+import com.intellij.openapi.util.Condition;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
import com.intellij.util.ArrayUtil;
+import com.intellij.util.containers.ContainerUtil;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
+import org.junit.Assert;
+
+import java.util.List;
/**
* @author anna
@@ -73,6 +79,17 @@ public abstract class IGQuickFixesTestCase extends JavaCodeInsightFixtureTestCas
return PluginPathManager.getPluginHomePath("InspectionGadgets") + "/test/com/siyeh/igfixes/";
}
+ protected void assertQuickfixNotAvailable() {
+ assertQuickfixNotAvailable(myDefaultHint);
+ }
+
+ protected void assertQuickfixNotAvailable(final String quickfixName) {
+ final String testName = getTestName(false);
+ myFixture.configureByFile(getRelativePath() + "/" + testName + ".java");
+ assertEmpty("Quickfix \'" + quickfixName + "\' is available but should not",
+ myFixture.filterAvailableIntentions(quickfixName));
+ }
+
protected void doTest() {
assertNotNull(myDefaultHint);
final String testName = getTestName(false);
@@ -86,12 +103,36 @@ public abstract class IGQuickFixesTestCase extends JavaCodeInsightFixtureTestCas
protected void doTest(final String testName, final String hint) {
myFixture.configureByFile(getRelativePath() + "/" + testName + ".java");
- final IntentionAction action = myFixture.findSingleIntention(hint);
+ final IntentionAction action = findIntention(hint);
assertNotNull(action);
myFixture.launchAction(action);
myFixture.checkResultByFile(getRelativePath() + "/" + testName + ".after.java");
}
+ public IntentionAction findIntention(@NotNull final String hint) {
+ final List<IntentionAction> availableIntentions =
+ ContainerUtil.findAll(myFixture.getAvailableIntentions(), new Condition<IntentionAction>() {
+ @Override
+ public boolean value(final IntentionAction intentionAction) {
+ return intentionAction instanceof QuickFixWrapper;
+ }
+ });
+ final List<IntentionAction> list = ContainerUtil.findAll(availableIntentions, new Condition<IntentionAction>() {
+ @Override
+ public boolean value(IntentionAction intentionAction) {
+ return intentionAction.getText().equals(hint);
+ }
+ });
+ if (list.isEmpty()) {
+ Assert.fail("\"" + hint + "\" not in " + list);
+ }
+ else if (list.size() > 1) {
+ Assert.fail("Too many quickfixes found for \"" + hint + "\": " + list + "]");
+ }
+ return list.get(0);
+ }
+
+
protected void doExpressionTest(
String hint,
@Language(value = "JAVA", prefix = "class $X$ {{System.out.print(", suffix = ");}}") @NotNull @NonNls String before,
@@ -109,7 +150,7 @@ public abstract class IGQuickFixesTestCase extends JavaCodeInsightFixtureTestCas
protected void doTest(String hint, @Language("JAVA") @NotNull @NonNls String before, @Language("JAVA") @NotNull @NonNls String after) {
before = before.replace("/**/", "<caret>");
myFixture.configureByText(JavaFileType.INSTANCE, before);
- final IntentionAction intention = myFixture.findSingleIntention(hint);
+ final IntentionAction intention = findIntention(hint);
assertNotNull(intention);
myFixture.launchAction(intention);
myFixture.checkResult(after);