diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java index c2655b28e60e..c1ff86e4208a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java @@ -15,8 +15,8 @@ */ package com.intellij.codeInspection; -import com.intellij.codeInspection.ex.InspectionProfileImpl; -import com.intellij.codeInspection.ex.InspectionToolRegistrar; +import com.intellij.codeInsight.daemon.HighlightDisplayKey; +import com.intellij.codeInspection.ex.*; import com.intellij.openapi.util.JDOMUtil; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.testFramework.LightIdeaTestCase; @@ -25,6 +25,8 @@ import org.jdom.Element; import org.jdom.JDOMException; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import static com.intellij.testFramework.PlatformTestUtil.assertElementsEqual; @@ -171,4 +173,51 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.writeExternal(copy); assertElementsEqual(element, copy); } + + public void testLockProfile() throws Exception { + + final List list = new ArrayList(); + list.add(createTool("foo")); + + InspectionToolRegistrar registrar = new InspectionToolRegistrar(null) { + @Override + public List createTools() { + LocalInspectionEP foo = new LocalInspectionEP(); + foo.shortName = "foo"; + return list; + } + }; + + InspectionProfileImpl profile = new InspectionProfileImpl("Foo", registrar, InspectionProfileManager.getInstance()); + profile.setBaseProfile(null); + List tools = profile.getAllTools(); + assertEquals(1, tools.size()); + ModifiableModel model = profile.getModifiableModel(); + model.lockProfile(true); + model.commit(); + Element element = new Element("element"); + profile.writeExternal(element); + + list.add(createTool("bar")); + + profile = new InspectionProfileImpl("Foo", registrar, InspectionProfileManager.getInstance()); + profile.readExternal(element); + + profile.setBaseProfile(null); + tools = profile.getAllTools(); + assertEquals(2, tools.size()); + + assertTrue(profile.isProfileLocked()); + assertFalse(profile.isToolEnabled(HighlightDisplayKey.find("bar"))); + } + + private static LocalInspectionToolWrapper createTool(String s) { + LocalInspectionEP foo = new LocalInspectionEP(); + foo.shortName = s; + foo.displayName = s; + foo.groupDisplayName = s; + foo.level = "ERROR"; + foo.enabledByDefault = true; + return new LocalInspectionToolWrapper(foo); + } }