Search in sources :

Example 11 with MapDataContext

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

the class ConfigurationRefactoringsTest method testRenameJUnitPackage.

public void testRenameJUnitPackage() throws IOException {
    PsiPackage psiPackage = mySource.createPackage("pkg");
    JUnitConfiguration configuration = createJUnitConfiguration(psiPackage, AllInPackageConfigurationProducer.class, new MapDataContext());
    rename(psiPackage, "pkg2");
    checkPackage("pkg2", configuration);
    PsiPackage outer = mySource.createPackage("outerPkg");
    move(JavaPsiFacade.getInstance(myProject).findPackage("pkg2"), outer.getQualifiedName());
    checkPackage("outerPkg.pkg2", configuration);
    rename(outer, "outer2");
    checkPackage("outer2.pkg2", configuration);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration)

Example 12 with MapDataContext

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

the class ContextConfigurationTest method testMethodInAbstractJUnit3TestCase.

public void testMethodInAbstractJUnit3TestCase() throws Exception {
    String packageName = "abstractTests";
    String shortName = "AbstractTestImpl1";
    String qualifiedName = StringUtil.getQualifiedName(packageName, shortName);
    PsiClass psiClass = findClass(getModule1(), qualifiedName);
    PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, true)[0];
    MapDataContext dataContext = new MapDataContext();
    dataContext.put(CommonDataKeys.PROJECT, myProject);
    if (LangDataKeys.MODULE.getData(dataContext) == null) {
        dataContext.put(LangDataKeys.MODULE, ModuleUtilCore.findModuleForPsiElement(testMethod));
    }
    dataContext.put(Location.DATA_KEY, MethodLocation.elementInClass(testMethod, psiClass));
    ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    RunnerAndConfigurationSettings settings = context.getConfiguration();
    JUnitConfiguration configuration = (JUnitConfiguration) settings.getConfiguration();
    checkClassName(qualifiedName, configuration);
    checkMethodName(METHOD_NAME, configuration);
    checkPackage(packageName, configuration);
    checkGeneretedName(configuration, shortName + "." + METHOD_NAME);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings)

Example 13 with MapDataContext

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

the class ContextConfigurationTest method testJUnitDefaultPackage.

public void testJUnitDefaultPackage() {
    PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
    PsiPackage psiPackage = JUnitUtil.getContainingPackage(psiClass);
    PsiPackage defaultPackage = psiPackage.getParentPackage();
    final Module module = ModuleUtil.findModuleForPsiElement(psiClass);
    final MapDataContext dataContext = new MapDataContext();
    dataContext.put(DataConstants.MODULE, module);
    JUnitConfiguration configuration = createJUnitConfiguration(defaultPackage, AllInPackageConfigurationProducer.class, dataContext);
    checkTestObject(JUnitConfiguration.TEST_PACKAGE, configuration);
    checkPackage("", configuration);
    checkGeneretedName(configuration, "All in " + module.getName());
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module)

Example 14 with MapDataContext

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

the class OverrideImplement15Test method testInAnnotationType.

public void testInAnnotationType() {
    String name = getTestName(false);
    configureByFile(BASE_DIR + "before" + name + ".java");
    int offset = getEditor().getCaretModel().getOffset();
    PsiElement context = getFile().findElementAt(offset);
    final PsiClass aClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
    assertTrue(aClass != null && aClass.isAnnotationType());
    final JavaOverrideMethodsHandler handler = new JavaOverrideMethodsHandler();
    assertTrue(handler.isValidFor(getEditor(), getFile()));
    assertFalse(handler.isAvailableForQuickList(getEditor(), getFile(), new MapDataContext()));
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) JavaOverrideMethodsHandler(com.intellij.codeInsight.generation.JavaOverrideMethodsHandler)

Example 15 with MapDataContext

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

the class ConfigurationsTest method testCreateConfiguration.

public void testCreateConfiguration() throws IOException, ExecutionException {
    Module module1 = getModule1();
    PsiClass psiClass = findTestA(module1);
    JUnitConfiguration configuration = createConfiguration(psiClass);
    assertEquals(Collections.singleton(module1), ContainerUtilRt.newHashSet(configuration.getModules()));
    checkClassName(psiClass.getQualifiedName(), configuration);
    assertEquals(psiClass.getName(), configuration.getName());
    checkTestObject(JUnitConfiguration.TEST_CLASS, configuration);
    Module module2 = getModule2();
    Assertion.compareUnordered(new Module[] { module1, module2 }, configuration.getValidModules());
    PsiClass innerTest = findClass(module1, INNER_TEST_NAME);
    configuration = createJUnitConfiguration(innerTest, TestInClassConfigurationProducer.class, new MapDataContext());
    checkClassName(RT_INNER_TEST_NAME, configuration);
    checkCanRun(configuration);
    PsiMethod[] testMethod = innerTest.findMethodsByName("test", false);
    assertEquals(1, testMethod.length);
    configuration = createConfiguration(testMethod[0]);
    checkClassName(RT_INNER_TEST_NAME, configuration);
    checkMethodName("test", configuration);
    checkTestObject(JUnitConfiguration.TEST_METHOD, configuration);
    checkCanRun(configuration);
    PsiMethod mainMethod = innerTest.findMethodsByName("main", false)[0];
    ApplicationConfiguration appConfiguration = createConfiguration(mainMethod);
    assertEquals(RT_INNER_TEST_NAME, appConfiguration.MAIN_CLASS_NAME);
    checkCanRun(configuration);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) Module(com.intellij.openapi.module.Module) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

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