Search in sources :

Example 61 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class JUnit5AcceptanceTest method testFactoryMethods.

@Test
void testFactoryMethods() {
    doTest(() -> {
        PsiClass aClass = myFixture.addClass("class MyTest {@org.junit.jupiter.api.TestFactory java.util.List<org.junit.jupiter.api.DynamicTest> tests() {return null;}}");
        PsiMethod factoryMethod = aClass.getMethods()[0];
        assertNotNull(factoryMethod);
        assertTrue(JUnitUtil.isTestAnnotated(factoryMethod));
    });
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Test(org.junit.jupiter.api.Test)

Example 62 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class JUnit5AcceptanceTest method recognizedInnerClassesWithTestMethods.

@Test
void recognizedInnerClassesWithTestMethods() {
    doTest(() -> {
        PsiClass aClass = myFixture.addClass("import org.junit.jupiter.api.*; class MyTest {@Nested class NTest { @Test void method() {}}}");
        assertTrue(JUnitUtil.isTestClass(aClass, false, false));
        PsiClass innerClass = aClass.getInnerClasses()[0];
        assertTrue(JUnitUtil.isTestClass(innerClass));
        assertTrue(JUnitUtil.isTestMethod(MethodLocation.elementInClass(innerClass.getMethods()[0], innerClass)));
    });
}
Also used : PsiClass(com.intellij.psi.PsiClass) Test(org.junit.jupiter.api.Test)

Example 63 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class JUnitConfigurationModel method applyTo.

private void applyTo(final JUnitConfiguration.Data data, final Module module) {
    final String testObject = getTestObject();
    final String className = getJUnitTextValue(CLASS);
    data.TEST_OBJECT = testObject;
    if (testObject != JUnitConfiguration.TEST_PACKAGE && testObject != JUnitConfiguration.TEST_PATTERN && testObject != JUnitConfiguration.TEST_DIRECTORY && testObject != JUnitConfiguration.TEST_CATEGORY && testObject != JUnitConfiguration.BY_SOURCE_CHANGES) {
        try {
            data.METHOD_NAME = getJUnitTextValue(METHOD);
            final PsiClass testClass = !myProject.isDefault() && !StringUtil.isEmptyOrSpaces(className) ? JUnitUtil.findPsiClass(className, module, myProject) : null;
            if (testClass != null && testClass.isValid()) {
                data.setMainClass(testClass);
            } else {
                data.MAIN_CLASS_NAME = className;
            }
        } catch (ProcessCanceledException | IndexNotReadyException e) {
            data.MAIN_CLASS_NAME = className;
        }
    } else if (testObject != JUnitConfiguration.BY_SOURCE_CHANGES) {
        if (testObject == JUnitConfiguration.TEST_PACKAGE) {
            data.PACKAGE_NAME = getJUnitTextValue(ALL_IN_PACKAGE);
        } else if (testObject == JUnitConfiguration.TEST_DIRECTORY) {
            data.setDirName(getJUnitTextValue(DIR));
        } else if (testObject == JUnitConfiguration.TEST_CATEGORY) {
            data.setCategoryName(getJUnitTextValue(CATEGORY));
        } else {
            final LinkedHashSet<String> set = new LinkedHashSet<>();
            final String[] patterns = getJUnitTextValue(PATTERN).split("\\|\\|");
            for (String pattern : patterns) {
                if (pattern.length() > 0) {
                    set.add(pattern);
                }
            }
            data.setPatterns(set);
        }
        data.MAIN_CLASS_NAME = "";
        data.METHOD_NAME = "";
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiClass(com.intellij.psi.PsiClass) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 64 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class JUnitRerunFailedTestsTest method testIgnoreRenamedMethodInRerunFailed.

public void testIgnoreRenamedMethodInRerunFailed() throws Exception {
    final PsiClass baseClass = myFixture.addClass("abstract class ATest extends junit.framework.TestCase {" + "  public void testMe() {}\n" + "}");
    myFixture.addClass("public class ChildTest extends ATest {}");
    final SMTestProxy testProxy = new SMTestProxy("testMe", false, "java:test://ChildTest.testMe");
    final Project project = getProject();
    final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    testProxy.setLocator(JavaTestLocator.INSTANCE);
    final String presentation = TestMethods.getTestPresentation(testProxy, project, searchScope);
    assertEquals("ChildTest,testMe", presentation);
    WriteCommandAction.runWriteCommandAction(project, () -> {
        baseClass.getMethods()[0].setName("testName2");
    });
    assertNull(TestMethods.getTestPresentation(testProxy, project, searchScope));
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass)

Example 65 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class JUnitRerunFailedTestsTest method testIncludeMethodsToRerunFromChildClass.

public void testIncludeMethodsToRerunFromChildClass() throws Exception {
    myFixture.addClass("abstract class ATest extends junit.framework.TestCase {" + "  public void testMe() {}\n" + "}");
    myFixture.addClass("public class ChildTest extends ATest {}");
    final SMTestProxy testProxy = new SMTestProxy("testMe", false, "java:test://ChildTest.testMe");
    final Project project = getProject();
    final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    testProxy.setLocator(JavaTestLocator.INSTANCE);
    final Location location = testProxy.getLocation(project, searchScope);
    assertNotNull(location);
    assertInstanceOf(location, MethodLocation.class);
    //navigation to the method in abstract super class
    final PsiElement element = location.getPsiElement();
    assertInstanceOf(element, PsiMethod.class);
    final PsiMethod method = (PsiMethod) element;
    assertEquals("testMe", method.getName());
    final PsiClass containingClass = method.getContainingClass();
    assertNotNull(containingClass);
    assertEquals("ATest", containingClass.getQualifiedName());
    //include method "from" child class to rerun
    final String presentation = TestMethods.getTestPresentation(testProxy, project, searchScope);
    assertEquals("ChildTest,testMe", presentation);
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Aggregations

PsiClass (com.intellij.psi.PsiClass)598 PsiElement (com.intellij.psi.PsiElement)113 PsiMethod (com.intellij.psi.PsiMethod)97 Nullable (org.jetbrains.annotations.Nullable)75 NotNull (org.jetbrains.annotations.NotNull)60 Project (com.intellij.openapi.project.Project)59 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)57 Module (com.intellij.openapi.module.Module)55 PsiFile (com.intellij.psi.PsiFile)49 VirtualFile (com.intellij.openapi.vfs.VirtualFile)47 ArrayList (java.util.ArrayList)37 PsiField (com.intellij.psi.PsiField)36 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)25 Location (com.intellij.execution.Location)20 File (java.io.File)16 HashSet (java.util.HashSet)16 PsiClassType (com.intellij.psi.PsiClassType)15 PsiPackage (com.intellij.psi.PsiPackage)15 List (java.util.List)15 PsiType (com.intellij.psi.PsiType)13