fix profiles test
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 21 Jul 2016 15:46:24 +0000 (17:46 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 21 Jul 2016 15:46:24 +0000 (17:46 +0200)
java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt
platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt

index d13b9b9634196abc33058d3e5bac5ec714f52253..1b150cf11b136bc04da77557caabe325c6a02e70 100644 (file)
@@ -99,28 +99,30 @@ internal class ProjectInspectionManagerTest {
   }
 
   @Test fun `profiles`() {
-    loadAndUseProject(tempDirManager, {
-      it.path
-    }) { project ->
-      val projectInspectionProfileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
-
-      assertThat(projectInspectionProfileManager.state).isEmpty()
-
-      // cause to use app profile
-      runInInitMode {
-        val currentProfile = projectInspectionProfileManager.currentProfile
-        assertThat(currentProfile.isProjectLevel).isTrue()
-        currentProfile.disableTool("Convert2Diamond", project)
-      }
-
-      project.saveStore()
-
-      val inspectionDir = Paths.get(project.stateStore.stateStorageManager.expandMacros(PROJECT_CONFIG_DIR), "inspectionProfiles")
-      val file = inspectionDir.resolve("profiles_settings.xml")
-
-      assertThat(file).doesNotExist()
-      val profileFile = inspectionDir.resolve("Project_Default.xml")
-      assertThat(profileFile.readText()).isEqualTo("""
+    runInInitMode {
+      loadAndUseProject(tempDirManager, {
+        it.path
+      }) { project ->
+        val projectInspectionProfileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
+        projectInspectionProfileManager.forceLoadSchemes()
+
+        assertThat(projectInspectionProfileManager.state).isEmpty()
+
+        // cause to use app profile
+        runInInitMode {
+          val currentProfile = projectInspectionProfileManager.currentProfile
+          assertThat(currentProfile.isProjectLevel).isTrue()
+          currentProfile.disableTool("Convert2Diamond", project)
+        }
+
+        project.saveStore()
+
+        val inspectionDir = Paths.get(project.stateStore.stateStorageManager.expandMacros(PROJECT_CONFIG_DIR), "inspectionProfiles")
+        val file = inspectionDir.resolve("profiles_settings.xml")
+
+        assertThat(file).doesNotExist()
+        val profileFile = inspectionDir.resolve("Project_Default.xml")
+        assertThat(profileFile.readText()).isEqualTo("""
       <component name="InspectionProjectProfileManager">
         <profile version="1.0">
           <option name="myName" value="Project Default" />
@@ -128,7 +130,7 @@ internal class ProjectInspectionManagerTest {
         </profile>
       </component>""".trimIndent())
 
-      profileFile.write("""
+        profileFile.write("""
       <component name="InspectionProjectProfileManager">
         <profile version="1.0">
           <option name="myName" value="Project Default" />
@@ -136,10 +138,11 @@ internal class ProjectInspectionManagerTest {
         </profile>
       </component>""".trimIndent())
 
-      project.baseDir.refresh(false, true)
-      (ProjectManager.getInstance() as StoreAwareProjectManager).flushChangedAlarm()
-      runInInitMode {
-        assertThat(projectInspectionProfileManager.currentProfile.getToolDefaultState("Convert2Diamond", project).level).isEqualTo(HighlightDisplayLevel.ERROR)
+        project.baseDir.refresh(false, true)
+        (ProjectManager.getInstance() as StoreAwareProjectManager).flushChangedAlarm()
+        runInInitMode {
+          assertThat(projectInspectionProfileManager.currentProfile.getToolDefaultState("Convert2Diamond", project).level).isEqualTo(HighlightDisplayLevel.ERROR)
+        }
       }
     }
   }
index 7566344f916d5777007d7bd468d447129a516c30..2dc7293e754333fcad69ad4f1a9aae35b381cf4d 100644 (file)
@@ -43,6 +43,7 @@ import com.intellij.util.xmlb.Accessor
 import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
 import com.intellij.util.xmlb.XmlSerializer
 import org.jdom.Element
+import org.jetbrains.annotations.TestOnly
 import java.util.concurrent.CompletableFuture
 import java.util.function.Function
 
@@ -139,6 +140,12 @@ class ProjectInspectionProfileManager(val project: Project,
     })
   }
 
+  @TestOnly
+  fun forceLoadSchemes() {
+    LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode)
+    schemeManager.loadSchemes()
+  }
+
   fun isCurrentProfileInitialized() = currentProfile.wasInitialized()
 
   @Synchronized override fun updateProfile(profile: Profile) {