Search in sources :

Example 1 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class CCTaskFileActionTest method getActionEvent.

@NotNull
private TestActionEvent getActionEvent(VirtualFile virtualFile, AnAction action) {
    MapDataContext context = new MapDataContext();
    context.put(CommonDataKeys.VIRTUAL_FILE, virtualFile);
    context.put(CommonDataKeys.PROJECT, getProject());
    return new TestActionEvent(context, action);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) TestActionEvent(com.intellij.testFramework.TestActionEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class JavaFileTemplatesTest method testManyTemplates.

public void testManyTemplates() {
    FileTemplateManagerImpl templateManager = (FileTemplateManagerImpl) FileTemplateManager.getInstance(getProject());
    templateManager.getState().RECENT_TEMPLATES.clear();
    FileTemplate[] before = templateManager.getAllTemplates();
    try {
        for (int i = 0; i < 30; i++) {
            templateManager.addTemplate("foo" + i, "java");
        }
        AnAction[] children = new CreateFromTemplateGroup().getChildren(new TestActionEvent(new TestDataProvider(getProject())));
        assertEquals(3, children.length);
        assertTrue(IdeBundle.message("action.from.file.template").equals(children[0].getTemplatePresentation().getText()));
    } finally {
        templateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(before));
        templateManager.getState().RECENT_TEMPLATES.clear();
    }
}
Also used : TestDataProvider(com.intellij.testFramework.TestDataProvider) FileTemplateManagerImpl(com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) TestActionEvent(com.intellij.testFramework.TestActionEvent) CreateFromTemplateGroup(com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup)

Example 3 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class JavaCallHierarchyTest method testActionAvailableInXml.

public void testActionAvailableInXml() throws Exception {
    configureByText(XmlFileType.INSTANCE, "<foo>java.lang.Str<caret>ing</foo>");
    BrowseTypeHierarchyAction action = new BrowseTypeHierarchyAction();
    TestActionEvent e = new TestActionEvent(action);
    action.beforeActionPerformedUpdate(e);
    assertTrue(e.getPresentation().isEnabled() && e.getPresentation().isVisible());
}
Also used : TestActionEvent(com.intellij.testFramework.TestActionEvent) BrowseTypeHierarchyAction(com.intellij.ide.hierarchy.actions.BrowseTypeHierarchyAction)

Example 4 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class RunLineMarkerTest method testTestClassWithMain.

public void testTestClassWithMain() throws Exception {
    myFixture.addClass("package junit.framework; public class TestCase {}");
    myFixture.configureByText("MainTest.java", "public class <caret>MainTest extends junit.framework.TestCase {\n" + "    public static void main(String[] args) {\n" + "    }\n" + "    public void testFoo() {\n" + "    }\n" + "}");
    List<GutterMark> marks = myFixture.findGuttersAtCaret();
    assertEquals(1, marks.size());
    GutterIconRenderer mark = (GutterIconRenderer) marks.get(0);
    ActionGroup group = mark.getPopupMenuActions();
    assertNotNull(group);
    TestActionEvent event = new TestActionEvent();
    List<AnAction> list = ContainerUtil.findAll(group.getChildren(event), action -> {
        TestActionEvent actionEvent = new TestActionEvent();
        action.update(actionEvent);
        String text = actionEvent.getPresentation().getText();
        return text != null && text.startsWith("Run ") && text.endsWith("'");
    });
    assertEquals(list.toString(), 2, list.size());
    list.get(0).update(event);
    assertEquals("Run 'MainTest.main()'", event.getPresentation().getText());
    list.get(1).update(event);
    assertEquals("Run 'MainTest'", event.getPresentation().getText());
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) GutterMark(com.intellij.codeInsight.daemon.GutterMark) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 5 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project android by JetBrains.

the class AndroidRenameTest method checkAndRenameUsingHandler.

private void checkAndRenameUsingHandler(String newName) {
    final RenameElementAction action = new RenameElementAction();
    final AnActionEvent e = new TestActionEvent(DataManager.getInstance().getDataContext(myFixture.getEditor().getComponent()), action);
    action.update(e);
    assertTrue(e.getPresentation().isEnabled() && e.getPresentation().isVisible());
    // Note: This fails when trying to rename XML attribute values: Use myFixture.renameElementAtCaretUsingHandler() instead!
    myFixture.renameElementAtCaretUsingHandler(newName);
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TestActionEvent(com.intellij.testFramework.TestActionEvent) RenameElementAction(com.intellij.refactoring.actions.RenameElementAction)

Aggregations

TestActionEvent (com.intellij.testFramework.TestActionEvent)16 AnAction (com.intellij.openapi.actionSystem.AnAction)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 CreateFromTemplateGroup (com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup)2 FileTemplateManagerImpl (com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 RenameElementAction (com.intellij.refactoring.actions.RenameElementAction)2 MapDataContext (com.intellij.testFramework.MapDataContext)2 TestDataProvider (com.intellij.testFramework.TestDataProvider)2 Arrays (java.util.Arrays)2 List (java.util.List)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 IdeBundle (com.intellij.ide.IdeBundle)1 GotoRelatedSymbolAction (com.intellij.ide.actions.GotoRelatedSymbolAction)1 CreateFromTemplateAction (com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction)1 BrowseTypeHierarchyAction (com.intellij.ide.hierarchy.actions.BrowseTypeHierarchyAction)1 LanguageFormatting (com.intellij.lang.LanguageFormatting)1 LanguageImportStatements (com.intellij.lang.LanguageImportStatements)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1