Search in sources :

Example 1 with DirectoryAsPackageRenameHandler

use of com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler in project android by JetBrains.

the class RenameTest method sourceRoot.

@Test
public void sourceRoot() throws Exception {
    guiTest.importSimpleApplication();
    final Project project = guiTest.ideFrame().getProject();
    Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
        final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
        for (final VirtualFile sourceRoot : sourceRoots) {
            PsiDirectory directory = GuiQuery.getNonNull(() -> PsiManager.getInstance(project).findDirectory(sourceRoot));
            for (final RenameHandler handler : Extensions.getExtensions(RenameHandler.EP_NAME)) {
                if (handler instanceof DirectoryAsPackageRenameHandler) {
                    final RenameDialogFixture renameDialog = RenameDialogFixture.startFor(directory, handler, guiTest.robot());
                    assertFalse(renameDialog.warningExists(null));
                    renameDialog.setNewName(renameDialog.getNewName() + 1);
                    // 'Rename dialog' show a warning asynchronously to the text change, that's why we wait here for the
                    // warning to appear
                    Wait.seconds(1).expecting("error text to appear").until(() -> renameDialog.warningExists(AndroidBundle.message("android.refactoring.gradle.warning.rename.source.root")));
                    renameDialog.clickCancel();
                    return;
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DirectoryAsPackageRenameHandler(com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler) RenameDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.RenameDialogFixture) PsiDirectory(com.intellij.psi.PsiDirectory) DirectoryAsPackageRenameHandler(com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler) RenameHandler(com.intellij.refactoring.rename.RenameHandler) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Aggregations

RenameDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameDialogFixture)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 DirectoryAsPackageRenameHandler (com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler)1 RenameHandler (com.intellij.refactoring.rename.RenameHandler)1 Test (org.junit.Test)1