Search in sources :

Example 1 with TestDataProvider

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

the class JUnitRerunFailedTestsTest method testMultipleClassesInOneFile.

public void testMultipleClassesInOneFile() throws Exception {
    myFixture.configureByText("a.java", "public class Test1 {<caret>} public class Test2 {}");
    final IdeaTestApplication testApplication = IdeaTestApplication.getInstance();
    try {
        testApplication.setDataProvider(new TestDataProvider(myFixture.getProject()) {

            @Override
            public Object getData(@NonNls String dataId) {
                if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
                    return new VirtualFile[] { myFixture.getFile().getVirtualFile() };
                }
                return super.getData(dataId);
            }
        });
        final PsiElement psiElement = myFixture.getFile().findElementAt(getEditor().getCaretModel().getOffset());
        final PatternConfigurationProducer configurationProducer = RunConfigurationProducer.getInstance(PatternConfigurationProducer.class);
        assertFalse(configurationProducer.isMultipleElementsSelected(new ConfigurationContext(psiElement)));
    } finally {
        testApplication.setDataProvider(null);
    }
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) IdeaTestApplication(com.intellij.idea.IdeaTestApplication) TestDataProvider(com.intellij.testFramework.TestDataProvider) PsiElement(com.intellij.psi.PsiElement)

Example 2 with TestDataProvider

use of com.intellij.testFramework.TestDataProvider 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 TestDataProvider

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

the class JavaFileTemplatesTest method testCreateFromTemplateGroup.

public void testCreateFromTemplateGroup() {
    myFixture.configureByText("foo.java", "");
    AnAction[] children = new CreateFromTemplateGroup().getChildren(new TestActionEvent(new TestDataProvider(getProject())));
    assertTrue(Stream.of(children).noneMatch(action -> isTemplateAction(action, "Class")));
    assertTrue(Stream.of(children).anyMatch(action -> isTemplateAction(action, "Singleton")));
}
Also used : TestActionEvent(com.intellij.testFramework.TestActionEvent) IdeBundle(com.intellij.ide.IdeBundle) Arrays(java.util.Arrays) Stream(java.util.stream.Stream) FileTemplateManagerImpl(com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl) TestDataProvider(com.intellij.testFramework.TestDataProvider) LightCodeInsightFixtureTestCase(com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase) AnAction(com.intellij.openapi.actionSystem.AnAction) CreateFromTemplateGroup(com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup) CreateFromTemplateAction(com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction) TestDataProvider(com.intellij.testFramework.TestDataProvider) AnAction(com.intellij.openapi.actionSystem.AnAction) TestActionEvent(com.intellij.testFramework.TestActionEvent) CreateFromTemplateGroup(com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup)

Aggregations

TestDataProvider (com.intellij.testFramework.TestDataProvider)3 CreateFromTemplateGroup (com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup)2 FileTemplateManagerImpl (com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 TestActionEvent (com.intellij.testFramework.TestActionEvent)2 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 IdeBundle (com.intellij.ide.IdeBundle)1 CreateFromTemplateAction (com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction)1 IdeaTestApplication (com.intellij.idea.IdeaTestApplication)1 PsiElement (com.intellij.psi.PsiElement)1 LightCodeInsightFixtureTestCase (com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase)1 Arrays (java.util.Arrays)1 Stream (java.util.stream.Stream)1