Search in sources :

Example 21 with MapDataContext

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

the class ContextConfigurationTest method testRecreateJUnitClass.

public void testRecreateJUnitClass() throws IOException {
    createEmptyModule();
    addDependency(getModule2(), getModule1());
    PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
    PsiPackage psiPackage = JUnitUtil.getContainingPackage(psiClass);
    JUnitConfiguration configuration = createJUnitConfiguration(psiPackage, AllInPackageConfigurationProducer.class, new MapDataContext());
    configuration.getPersistentData().setScope(TestSearchScope.MODULE_WITH_DEPENDENCIES);
    configuration.setModule(getModule2());
    MapDataContext dataContext = new MapDataContext();
    dataContext.put(DataConstantsEx.RUNTIME_CONFIGURATION, configuration);
    configuration = createJUnitConfiguration(psiClass, TestInClassConfigurationProducer.class, dataContext);
    checkClassName(psiClass.getQualifiedName(), configuration);
    assertEquals(Collections.singleton(getModule2()), new HashSet(Arrays.asList(configuration.getModules())));
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) HashSet(java.util.HashSet)

Example 22 with MapDataContext

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

the class RenameModuleTest method testRename.

public void testRename() throws Exception {
    String moduleName = "module";
    String newModuleName = "moduleA";
    Module module = createModule(moduleName);
    assertEquals(moduleName, module.getName());
    MapDataContext context = new MapDataContext();
    context.put(LangDataKeys.MODULE_CONTEXT, module);
    final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
    assertNotNull(renameHandler);
    Messages.setTestInputDialog(new TestInputDialog() {

        @Override
        public String show(String message) {
            return null;
        }

        @Override
        public String show(String message, @Nullable InputValidator validator) {
            assertNotNull(validator);
            boolean canClose = validator.canClose(newModuleName);
            assertTrue(canClose);
            return newModuleName;
        }
    });
    renameHandler.invoke(myProject, PsiElement.EMPTY_ARRAY, context);
    assertEquals(newModuleName, module.getName());
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) InputValidator(com.intellij.openapi.ui.InputValidator) RenameHandler(com.intellij.refactoring.rename.RenameHandler) TestInputDialog(com.intellij.openapi.ui.TestInputDialog) Module(com.intellij.openapi.module.Module)

Example 23 with MapDataContext

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

the class MavenDomTestCase method doRename.

protected void doRename(final VirtualFile f, String value) throws IOException {
    final MapDataContext context = createRenameDataContext(f, value);
    final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
    assertNotNull(renameHandler);
    invokeRename(context, renameHandler);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) RenameHandler(com.intellij.refactoring.rename.RenameHandler) PsiElementRenameHandler(com.intellij.refactoring.rename.PsiElementRenameHandler)

Example 24 with MapDataContext

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

the class CCShowPreviewTest method getActionEvent.

TestActionEvent getActionEvent(AnAction action, PsiFile psiFile) {
    MapDataContext context = new MapDataContext();
    context.put(CommonDataKeys.PSI_FILE, psiFile);
    context.put(CommonDataKeys.PROJECT, getProject());
    context.put(LangDataKeys.MODULE, myFixture.getModule());
    return new TestActionEvent(context, action);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 25 with MapDataContext

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

the class TestConfigurationTesting method createContext.

@NotNull
public static ConfigurationContext createContext(@NotNull Project project, @NotNull PsiElement psiElement) {
    MapDataContext dataContext = new MapDataContext();
    dataContext.put(CommonDataKeys.PROJECT, project);
    if (LangDataKeys.MODULE.getData(dataContext) == null) {
        dataContext.put(LangDataKeys.MODULE, ModuleUtilCore.findModuleForPsiElement(psiElement));
    }
    dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiElement));
    return ConfigurationContext.getFromContext(dataContext);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MapDataContext (com.intellij.testFramework.MapDataContext)25 PsiClass (com.intellij.psi.PsiClass)8 Module (com.intellij.openapi.module.Module)6 RenameHandler (com.intellij.refactoring.rename.RenameHandler)4 PsiPackage (com.intellij.psi.PsiPackage)3 PsiElementRenameHandler (com.intellij.refactoring.rename.PsiElementRenameHandler)3 NotNull (org.jetbrains.annotations.NotNull)3 JavaFxPropertyRenameHandler (org.jetbrains.plugins.javaFX.refactoring.JavaFxPropertyRenameHandler)3 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)2 TestActionEvent (com.intellij.testFramework.TestActionEvent)2 JavaOverrideMethodsHandler (com.intellij.codeInsight.generation.JavaOverrideMethodsHandler)1 PsiLocation (com.intellij.execution.PsiLocation)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 DataProvider (com.intellij.openapi.actionSystem.DataProvider)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1