use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class ConfigurationsTest method testRenameMethod.
@Test
public void testRenameMethod() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final String className = psiClass.getName();
final TestNGConfiguration configuration = createConfiguration(project);
final PsiMethod method = findTestMethod(psiClass);
configuration.beMethodConfiguration(new PsiLocation<>(project, method));
final String newMethodName = "renamedTest";
final RenameRefactoring renameMethod = RefactoringFactory.getInstance(project).createRename(method, newMethodName);
renameMethod.setSearchInComments(false);
renameMethod.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameMethod.run();
}
}.execute();
Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
final PsiMethod notATestMethod = findNotATestMethod(psiClass);
final RenameRefactoring renameNotATestMethod1 = RefactoringFactory.getInstance(project).createRename(notATestMethod, "bbbbb");
renameNotATestMethod1.setSearchInComments(false);
renameNotATestMethod1.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameNotATestMethod1.run();
}
}.execute();
Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class ConfigurationsTest method testCreateFromContext.
@Test
public void testCreateFromContext() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final TestNGInClassConfigurationProducer producer = new TestNGInClassConfigurationProducer();
final MapDataContext dataContext = new MapDataContext();
dataContext.put(CommonDataKeys.PROJECT, project);
dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(psiClass));
dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiClass));
final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
assert fromContext != null;
final RunnerAndConfigurationSettings config = fromContext.getConfigurationSettings();
final RunConfiguration runConfiguration = config.getConfiguration();
Assert.assertTrue(runConfiguration instanceof TestNGConfiguration);
TestNGConfigurationType t = (TestNGConfigurationType) runConfiguration.getType();
Assert.assertTrue(t.isConfigurationByLocation(runConfiguration, new PsiLocation(project, psiClass)));
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class ConfigurationsTest method testClassRename.
@Test
public void testClassRename() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final TestNGConfiguration configuration = createConfiguration(project);
configuration.beClassConfiguration(psiClass);
final String newName = "Testt1";
final RenameRefactoring renameClass = RefactoringFactory.getInstance(project).createRename(psiClass, newName);
renameClass.setSearchInComments(false);
renameClass.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameClass.run();
}
}.execute();
Assert.assertEquals(newName, configuration.getPersistantData().getMainClassName());
final PsiMethod notATestMethod = findNotATestMethod(psiClass);
final RenameRefactoring renameNotATestMethod = RefactoringFactory.getInstance(project).createRename(notATestMethod, "aaaa");
renameNotATestMethod.setSearchInComments(false);
renameNotATestMethod.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameNotATestMethod.run();
}
}.execute();
Assert.assertEquals(configuration.getPersistantData().getMainClassName(), newName);
Assert.assertEquals(configuration.getPersistantData().getMethodName(), "");
Assert.assertEquals(configuration.getPersistantData().TEST_OBJECT, TestType.CLASS.getType());
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class DetectClassesToRunTest method testBeforeClassIsIncludedIfRunOnlyOneMethod.
@Test
public void testBeforeClassIsIncludedIfRunOnlyOneMethod() throws Exception {
final PsiClass aClass = myFixture.addClass("package a; public class AConfig {" + "@org.testng.annotations.BeforeClass public void setup(){}\n" + "@org.testng.annotations.Test public void testOne(){}\n" + "}");
doTestMethodConfiguration(aClass, aClass.getMethods()[1]);
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class DetectClassesToRunTest method testNonRelatedIncludedWhenConfigIsLocatedInSuperclassInAnotherPackage.
@Test
public void testNonRelatedIncludedWhenConfigIsLocatedInSuperclassInAnotherPackage() throws Exception {
myFixture.addClass("package a; public class AConfig {@org.testng.annotations.BeforeClass public void setup(){}}");
final PsiClass emptyClassWithSuperConfig = myFixture.addClass("package p; import a.AConfig; public class BConfig extends AConfig {}");
final PsiClass testClass = myFixture.addClass("package p; public class ATest {@org.testng.annotations.Test public void testOne(){}}");
doTestPackageConfiguration(emptyClassWithSuperConfig, testClass);
}
Aggregations