mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
commenter tests: use utils to invoke actions
This commit is contained in:
@@ -20,9 +20,9 @@ import com.intellij.codeInsight.daemon.impl.DaemonListeners;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase;
|
||||
import com.intellij.codeInsight.generation.actions.CommentByBlockCommentAction;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -306,8 +306,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
|
||||
assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements());
|
||||
|
||||
CommentByBlockCommentAction action = new CommentByBlockCommentAction();
|
||||
action.actionPerformedImpl(getProject(), getEditor());
|
||||
EditorTestUtil.executeAction(getEditor(), IdeActions.ACTION_COMMENT_BLOCK);
|
||||
|
||||
assertEmpty(highlightErrors());
|
||||
|
||||
|
||||
+1
-10
@@ -22,7 +22,6 @@ import com.intellij.codeInsight.daemon.*;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.DeleteCatchFix;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||
import com.intellij.codeInsight.folding.CodeFoldingManager;
|
||||
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
|
||||
import com.intellij.codeInsight.hint.EditorHintListener;
|
||||
import com.intellij.codeInsight.intention.AbstractIntentionAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
@@ -58,7 +57,6 @@ import com.intellij.lang.annotation.ExternalAnnotator;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
@@ -337,7 +335,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
|
||||
List<HighlightInfo> infos = doHighlighting(HighlightSeverity.WARNING);
|
||||
assertEmpty(infos);
|
||||
|
||||
commentLine();
|
||||
PlatformTestUtil.invokeNamedAction(IdeActions.ACTION_COMMENT_LINE);
|
||||
infos = doHighlighting(HighlightSeverity.WARNING);
|
||||
|
||||
assertEquals(1, infos.size());
|
||||
@@ -626,14 +624,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
|
||||
assertEquals(markers.toString(), 3, markers.size());
|
||||
}
|
||||
|
||||
private static void commentLine() {
|
||||
WriteCommandAction.runWriteCommandAction(null, () -> {
|
||||
CommentByLineCommentAction action = new CommentByLineCommentAction();
|
||||
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", DataManager.getInstance().getDataContext()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void testChangeXmlIncludeLeadsToRehighlight() throws Exception {
|
||||
LanguageFilter[] extensions = ((CompositeLanguage)StdLanguages.XML).getLanguageExtensions();
|
||||
for (LanguageFilter extension : extensions) {
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
||||
public class CodeInsightTestCaseUtil {
|
||||
public static void doAction(CodeInsightTestCase testCase, AnAction action, String testName, String ext) throws Exception {
|
||||
testCase.configureByFile(testName + "." + ext);
|
||||
|
||||
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", DataManager.getInstance().getDataContext()));
|
||||
|
||||
testCase.checkResultByFile(testName + "_after." + ext);
|
||||
}
|
||||
|
||||
}
|
||||
+5
-10
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.generation.actions.CommentByBlockCommentAction;
|
||||
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -51,13 +48,11 @@ public class CommentInCustomFileTypesTest extends LightPlatformCodeInsightTestCa
|
||||
checkResultByFile("/codeInsight/commentInCustomFileType/line2_after.cs");
|
||||
}
|
||||
|
||||
private void performBlockCommentAction() {
|
||||
CommentByBlockCommentAction action = new CommentByBlockCommentAction();
|
||||
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", DataManager.getInstance().getDataContext()));
|
||||
private static void performBlockCommentAction() {
|
||||
PlatformTestUtil.invokeNamedAction(IdeActions.ACTION_COMMENT_BLOCK);
|
||||
}
|
||||
|
||||
private void performLineCommentAction() {
|
||||
CommentByLineCommentAction action = new CommentByLineCommentAction();
|
||||
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", DataManager.getInstance().getDataContext()));
|
||||
private static void performLineCommentAction() {
|
||||
PlatformTestUtil.invokeNamedAction(IdeActions.ACTION_COMMENT_LINE);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
|
||||
import com.intellij.codeInsight.highlighting.HighlightUsagesHandler;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.injected.editor.DocumentWindow;
|
||||
@@ -621,7 +620,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
}
|
||||
|
||||
protected static void lineComment() {
|
||||
new CommentByLineCommentAction().actionPerformedImpl(getProject(), getEditor());
|
||||
executeAction(IdeActions.ACTION_COMMENT_LINE);
|
||||
}
|
||||
|
||||
protected static void executeAction(@NonNls @NotNull final String actionId) {
|
||||
|
||||
@@ -436,7 +436,7 @@ public class PlatformTestUtil {
|
||||
final Presentation presentation = new Presentation();
|
||||
@SuppressWarnings("deprecation") final DataContext context = DataManager.getInstance().getDataContext();
|
||||
final AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "", context);
|
||||
action.update(event);
|
||||
action.beforeActionPerformedUpdate(event);
|
||||
Assert.assertTrue(presentation.isEnabled());
|
||||
action.actionPerformed(event);
|
||||
}
|
||||
|
||||
+1
-1
@@ -830,7 +830,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
return WriteCommandAction.runWriteCommandAction(getProject(), new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
action.update(event);
|
||||
action.beforeActionPerformedUpdate(event);
|
||||
|
||||
if (!event.getPresentation().isEnabled()) {
|
||||
return false;
|
||||
|
||||
@@ -17,13 +17,9 @@ package org.jetbrains.plugins.groovy
|
||||
|
||||
import com.intellij.codeInsight.generation.actions.CommentByBlockCommentAction
|
||||
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction
|
||||
import com.intellij.ide.DataManager
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
@@ -101,8 +97,7 @@ print 2
|
||||
|
||||
private void doTest(@NotNull String before, @NotNull String after, final AnAction action) {
|
||||
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, before)
|
||||
final DataContext dataContext = DataManager.instance.dataContextFromFocus.result
|
||||
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", dataContext))
|
||||
myFixture.testAction(action)
|
||||
myFixture.checkResult(after)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-9
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package com.intellij.lang.properties;
|
||||
|
||||
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -37,12 +36,7 @@ public class PropertiesCommenterTest extends LightPlatformCodeInsightTestCase {
|
||||
|
||||
private void doTest() {
|
||||
configureByFile("/propertiesFile/comment/before" + getTestName(false) + ".properties");
|
||||
performAction();
|
||||
PlatformTestUtil.invokeNamedAction(IdeActions.ACTION_COMMENT_LINE);
|
||||
checkResultByFile("/propertiesFile/comment/after" + getTestName(false) + ".properties");
|
||||
}
|
||||
|
||||
private static void performAction() {
|
||||
CommentByLineCommentAction action = new CommentByLineCommentAction();
|
||||
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", DataManager.getInstance().getDataContext()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,13 @@
|
||||
*/
|
||||
package com.jetbrains.python;
|
||||
|
||||
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.jetbrains.python.codeInsight.PyCodeInsightSettings;
|
||||
import com.jetbrains.python.documentation.docstrings.DocStringFormat;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
@@ -124,10 +121,7 @@ public class PyEditingTest extends PyTestCase {
|
||||
public void testUncommentWithSpace() throws Exception { // PY-980
|
||||
myFixture.configureByFile("/editing/uncommentWithSpace.before.py");
|
||||
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(0, 1));
|
||||
CommandProcessor.getInstance().executeCommand(myFixture.getProject(), () -> {
|
||||
CommentByLineCommentAction action = new CommentByLineCommentAction();
|
||||
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", DataManager.getInstance().getDataContext()));
|
||||
}, "", null);
|
||||
PlatformTestUtil.invokeNamedAction(IdeActions.ACTION_COMMENT_LINE);
|
||||
myFixture.checkResultByFile("/editing/uncommentWithSpace.after.py", true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user