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));
});
}
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)));
});
}
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 = "";
}
}
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));
}
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);
}
Aggregations