fix SingleInspectionProfilePanelTest idea/163.1513
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 14 Jul 2016 15:55:06 +0000 (17:55 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 14 Jul 2016 15:55:06 +0000 (17:55 +0200)
java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.kt
java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java
platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java
platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java
platform/testFramework/src/com/intellij/testFramework/inspections.kt

index c1e7340440779eb7daa7d3b27690059f5f9d3d93..37955a08bab82fe83cd1c74fe2e9ed3595d27a18 100644 (file)
@@ -20,11 +20,10 @@ import com.intellij.codeInspection.ex.InspectionProfileTest
 import com.intellij.codeInspection.ex.LocalInspectionToolWrapper
 import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection
 import com.intellij.openapi.project.ProjectManager
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager
 import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
 import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel
 import com.intellij.testFramework.LightIdeaTestCase
-import com.intellij.testFramework.LightPlatformTestCase
+import com.intellij.testFramework.createProfile
 import junit.framework.TestCase
 
 class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
@@ -37,25 +36,25 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
     val profile = profileManager.currentProfile
 
     val model = profile.modifiableModel
-    val panel = SingleInspectionProfilePanel(profileManager, LightPlatformTestCase.PROFILE, model, profile)
+    val panel = SingleInspectionProfilePanel(profileManager, profile.name, model, profile)
     panel.isVisible = true
     panel.reset()
 
     val tool = getInspection(model)
-    TestCase.assertEquals("", tool.myAdditionalJavadocTags)
+    assertEquals("", tool.myAdditionalJavadocTags)
     tool.myAdditionalJavadocTags = "foo"
     model.setModified(true)
     panel.apply()
     TestCase.assertEquals(1, InspectionProfileTest.countInitializedTools(model))
 
-    TestCase.assertEquals("foo", getInspection(profile).myAdditionalJavadocTags)
+    assertEquals("foo", getInspection(profile).myAdditionalJavadocTags)
     panel.disposeUI()
   }
 
   fun testModifyInstantiatedTool() {
     val project = ProjectManager.getInstance().defaultProject
     val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
-    val profile = profileManager.getProfile(LightPlatformTestCase.PROFILE) as InspectionProfileImpl
+    val profile = profileManager.createProfile(myInspection, myTestRootDisposable)
     profile.initInspectionTools(project)
 
     val originalTool = getInspection(profile)
@@ -63,7 +62,7 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
 
     val model = profile.modifiableModel
 
-    val panel = SingleInspectionProfilePanel(profileManager, LightPlatformTestCase.PROFILE, model, profile)
+    val panel = SingleInspectionProfilePanel(profileManager, profile.name, model, profile)
     panel.isVisible = true
     panel.reset()
     TestCase.assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1,
@@ -76,14 +75,14 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
     panel.apply()
     TestCase.assertEquals(1, InspectionProfileTest.countInitializedTools(model))
 
-    TestCase.assertEquals("bar", getInspection(profile).myAdditionalJavadocTags)
+    assertEquals("bar", getInspection(profile).myAdditionalJavadocTags)
     panel.disposeUI()
   }
 
   fun testDoNotChangeSettingsOnCancel() {
     val project = ProjectManager.getInstance().defaultProject
-    val profileManager = InspectionProjectProfileManager.getInstance(project)
-    val profile = profileManager.getProfile(LightPlatformTestCase.PROFILE) as InspectionProfileImpl
+    val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
+    val profile = profileManager.createProfile(myInspection, myTestRootDisposable)
     profile.initInspectionTools(project)
 
     val originalTool = getInspection(profile)
@@ -94,21 +93,20 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
     copyTool.myAdditionalJavadocTags = "foo"
     // this change IS NOT COMMITTED
 
-    TestCase.assertEquals("", getInspection(profile).myAdditionalJavadocTags)
+    assertEquals("", getInspection(profile).myAdditionalJavadocTags)
   }
 
   private fun getInspection(profile: InspectionProfileImpl): JavaDocLocalInspection {
-    val original = (profile.getInspectionTool(myInspection.shortName, LightPlatformTestCase.getProject()) as LocalInspectionToolWrapper?)!!
-    return original.tool as JavaDocLocalInspection
+    return (profile.getInspectionTool(myInspection.shortName, getProject()) as LocalInspectionToolWrapper?)!!.tool as JavaDocLocalInspection
   }
 
   override fun setUp() {
-//    InspectionProfileImpl.INIT_INSPECTIONS = true
+    InspectionProfileImpl.INIT_INSPECTIONS = true
     super.setUp()
   }
 
   override fun tearDown() {
-//    InspectionProfileImpl.INIT_INSPECTIONS = false
+    InspectionProfileImpl.INIT_INSPECTIONS = false
     super.tearDown()
   }
 
index ef50d793457dd0a70932558b4dda46dddf2def45..38d3adf9efe964780eb1d26724aa21247f1b0591 100644 (file)
@@ -77,7 +77,6 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 
 public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
@@ -89,7 +88,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
 
     final LocalInspectionTool[] tools = configureLocalInspectionTools();
 
-    InspectionsKt.configureInspections(tools, getProject(), Collections.emptyList(), getTestRootDisposable());
+    InspectionsKt.configureInspections(tools, getProject(), getTestRootDisposable());
 
     DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
     daemonCodeAnalyzer.prepareForTest();
index 0b2db26874167a7f9706fa19f12ec112f4cbd2cd..fbb0fb6f1f0f811a0d93f77639a3751292f482a8 100644 (file)
@@ -79,7 +79,6 @@ import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl;
 import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
 import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl;
 import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
-import com.intellij.profile.codeInspection.InspectionProfileManager;
 import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiFile;
@@ -114,7 +113,6 @@ import java.io.PrintStream;
 import java.lang.management.GarbageCollectorMXBean;
 import java.lang.management.ManagementFactory;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.function.Consumer;
 
@@ -122,8 +120,6 @@ import java.util.function.Consumer;
  * @author yole
  */
 public abstract class LightPlatformTestCase extends UsefulTestCase implements DataProvider {
-  @NonNls public static final String PROFILE = "Configurable";
-
   @NonNls private static final String LIGHT_PROJECT_MARK = "Light project: ";
 
   private static IdeaTestApplication ourApplication;
@@ -312,7 +308,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
 
     clearUncommittedDocuments(getProject());
 
-    InspectionsKt.configureInspections(localInspectionTools, getProject(), Collections.emptyList(), parentDisposable);
+    InspectionsKt.configureInspections(localInspectionTools, getProject(), parentDisposable);
 
     assertFalse(getPsiManager().isDisposed());
     Boolean passed = null;
@@ -453,7 +449,6 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
         lookupManager.hideActiveLookup();
       }
       ((StartupManagerImpl)StartupManager.getInstance(project)).prepareForNextTest();
-      InspectionProfileManager.getInstance().deleteProfile(PROFILE);
       if (ProjectManager.getInstance() == null) {
         exceptions.add(new AssertionError("Application components damaged"));
       }
index 7cbde5930c14cc29f68880bb33301c0709c45372..f4598e5e9994ed35394591d49eaf2fd4df3121ac 100644 (file)
@@ -1216,7 +1216,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
         PlatformTestCase.synchronizeTempDirVfs(tempDir);
 
         myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject());
-        InspectionsKt.configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), Collections.emptyList(), getTestRootDisposable());
+        InspectionsKt.configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), getTestRootDisposable());
 
         DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
         daemonCodeAnalyzer.prepareForTest();
index c846597c42b8a90a1113551bd35d6417afcfd2b1..a19db2c5340d60fb7e7623574eb37df7f6a6983a 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.testFramework
 
 import com.intellij.analysis.AnalysisScope
 import com.intellij.codeInspection.InspectionProfileEntry
+import com.intellij.codeInspection.LocalInspectionTool
 import com.intellij.codeInspection.ex.*
 import com.intellij.openapi.Disposable
 import com.intellij.openapi.project.Project
@@ -25,13 +26,13 @@ import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
 import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests
 import com.intellij.util.ReflectionUtil
 import org.jetbrains.annotations.TestOnly
+import java.util.*
 
 fun configureInspections(tools: Array<InspectionProfileEntry>,
                          project: Project,
-                         disabledInspections: Collection<String>,
-                         parentDisposable: Disposable) {
-  val profile = InspectionProfileImpl.createSimple(LightPlatformTestCase.PROFILE, project, tools.map { InspectionToolRegistrar.wrapTool(it) })
-  profile.disableToolByDefault(disabledInspections, project)
+                         parentDisposable: Disposable): InspectionProfileImpl {
+  val profile = InspectionProfileImpl.createSimple(UUID.randomUUID().toString(), project, tools.map { InspectionToolRegistrar.wrapTool(it) })
+//  profile.disableToolByDefault(disabledInspections, project)
 
   val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
 
@@ -49,6 +50,7 @@ fun configureInspections(tools: Array<InspectionProfileEntry>,
                                          profileManager.setCurrentProfile(profile)
                                          null
                                        })
+  return profile
 }
 
 @JvmOverloads
@@ -79,4 +81,8 @@ private fun clearAllToolsIn(profile: InspectionProfileImpl, project: Project) {
       ReflectionUtil.resetField(wrapper, InspectionProfileEntry::class.java, "myTool")
     }
   }
+}
+
+fun ProjectInspectionProfileManager.createProfile(localInspectionTool: LocalInspectionTool, disposable: Disposable): InspectionProfileImpl {
+  return configureInspections(arrayOf(localInspectionTool), project, disposable)
 }
\ No newline at end of file