use of com.intellij.testFramework.MapDataContext 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.testFramework.MapDataContext in project intellij-community by JetBrains.
the class MavenDomTestCase method createDataContext.
private MapDataContext createDataContext(VirtualFile f) throws IOException {
MapDataContext context = new MapDataContext();
context.put(CommonDataKeys.EDITOR, getEditor(f));
context.put(CommonDataKeys.PSI_FILE, getTestPsiFile(f));
context.put(CommonDataKeys.PSI_ELEMENT, TargetElementUtil.findTargetElement(getEditor(f), TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED));
return context;
}
use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.
the class MavenDomTestCase method assertCannotRename.
protected void assertCannotRename() throws Exception {
MapDataContext context = createRenameDataContext(myProjectPom, "new name");
RenameHandler handler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
if (handler == null)
return;
try {
invokeRename(context, handler);
} catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
if (!e.getMessage().startsWith("Cannot perform refactoring.")) {
throw e;
}
}
}
use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.
the class MavenDomTestCase method search.
protected List<PsiElement> search(VirtualFile file) throws IOException {
final MapDataContext context = createDataContext(file);
UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {
@Override
public Object getData(@NonNls String dataId) {
return context.getData(dataId);
}
});
PsiElement target = ((PsiElement2UsageTargetAdapter) targets[0]).getElement();
List<PsiReference> result = new ArrayList<>(ReferencesSearch.search(target).findAll());
return ContainerUtil.map(result, psiReference -> psiReference.getElement());
}
use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.
the class MavenDomTestCase method createRenameDataContext.
private MapDataContext createRenameDataContext(VirtualFile f, String value) throws IOException {
MapDataContext context = createDataContext(f);
context.put(PsiElementRenameHandler.DEFAULT_NAME, value);
return context;
}
Aggregations