Search in sources :

Example 11 with IdeaProjectTestFixture

use of com.intellij.testFramework.fixtures.IdeaProjectTestFixture in project android by JetBrains.

the class AndroidTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
    myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
    JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
    File moduleRoot = new File(myFixture.getTempDirPath());
    if (!moduleRoot.exists()) {
        assertTrue(moduleRoot.mkdirs());
    }
    initializeModuleFixtureBuilderWithSrcAndGen(moduleFixtureBuilder, moduleRoot.toString());
    ArrayList<MyAdditionalModuleData> modules = new ArrayList<>();
    configureAdditionalModules(projectBuilder, modules);
    myFixture.setUp();
    myFixture.setTestDataPath(getTestDataPath());
    myModule = moduleFixtureBuilder.getFixture().getModule();
    // Must be done before addAndroidFacet, and must always be done, even if a test provides
    // its own custom manifest file. However, in that case, we will delete it shortly below.
    createManifest();
    myFacet = addAndroidFacet(myModule);
    LanguageLevel languageLevel = getLanguageLevel();
    if (languageLevel != null) {
        LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(myModule.getProject());
        if (extension != null) {
            extension.setLanguageLevel(languageLevel);
        }
    }
    myFixture.copyDirectoryToProject(getResDir(), "res");
    myAdditionalModules = new ArrayList<>();
    for (MyAdditionalModuleData data : modules) {
        Module additionalModule = data.myModuleFixtureBuilder.getFixture().getModule();
        myAdditionalModules.add(additionalModule);
        AndroidFacet facet = addAndroidFacet(additionalModule);
        facet.setProjectType(data.myProjectType);
        String rootPath = getAdditionalModulePath(data.myDirName);
        myFixture.copyDirectoryToProject(getResDir(), rootPath + "/res");
        myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, rootPath + '/' + SdkConstants.FN_ANDROID_MANIFEST_XML);
        if (data.myIsMainModuleDependency) {
            ModuleRootModificationUtil.addDependency(myModule, additionalModule);
        }
    }
    if (providesCustomManifest()) {
        deleteManifest();
    }
    if (RenderSecurityManager.RESTRICT_READS) {
        // Unit test class loader includes disk directories which security manager does not allow access to
        RenderSecurityManager.sEnabled = false;
    }
    ArrayList<String> allowedRoots = new ArrayList<>();
    collectAllowedRoots(allowedRoots);
    registerAllowedRoots(allowedRoots, getTestRootDisposable());
    mySettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
    AndroidCodeStyleSettingsModifier.modify(mySettings);
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(mySettings);
    myUseCustomSettings = getAndroidCodeStyleSettings().USE_CUSTOM_SETTINGS;
    getAndroidCodeStyleSettings().USE_CUSTOM_SETTINGS = true;
    // Layoutlib rendering thread will be shutdown when the app is closed so do not report it as a leak
    ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication(), "Layoutlib");
}
Also used : JavaModuleFixtureBuilder(com.intellij.testFramework.builders.JavaModuleFixtureBuilder) ArrayList(java.util.ArrayList) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IdeaProjectTestFixture(com.intellij.testFramework.fixtures.IdeaProjectTestFixture) LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

IdeaProjectTestFixture (com.intellij.testFramework.fixtures.IdeaProjectTestFixture)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 IdeaTestFixtureFactory (com.intellij.testFramework.fixtures.IdeaTestFixtureFactory)3 File (java.io.File)3 Module (com.intellij.openapi.module.Module)2 JavaModuleFixtureBuilder (com.intellij.testFramework.builders.JavaModuleFixtureBuilder)2 JavaTestFixtureFactory (com.intellij.testFramework.fixtures.JavaTestFixtureFactory)2 LightTempDirTestFixtureImpl (com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl)2 ArrayList (java.util.ArrayList)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 GradleSettingsFile (com.android.tools.idea.gradle.parser.GradleSettingsFile)1 Projects.isLegacyIdeaAndroidProject (com.android.tools.idea.gradle.util.Projects.isLegacyIdeaAndroidProject)1 StartupManagerImpl (com.intellij.ide.startup.impl.StartupManagerImpl)1 Project (com.intellij.openapi.project.Project)1 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)1 Ref (com.intellij.openapi.util.Ref)1 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 LightProjectDescriptor (com.intellij.testFramework.LightProjectDescriptor)1 EmptyModuleFixtureBuilder (com.intellij.testFramework.builders.EmptyModuleFixtureBuilder)1