2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.codeInspection
18 import com.intellij.codeInspection.ex.InspectionProfileImpl
19 import com.intellij.codeInspection.ex.InspectionProfileTest
20 import com.intellij.codeInspection.ex.LocalInspectionToolWrapper
21 import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection
22 import com.intellij.openapi.project.ProjectManager
23 import com.intellij.profile.codeInspection.InspectionProjectProfileManager
24 import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
25 import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel
26 import com.intellij.testFramework.LightIdeaTestCase
27 import com.intellij.testFramework.LightPlatformTestCase
28 import junit.framework.TestCase
30 class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
31 private val myInspection = JavaDocLocalInspection()
34 fun testSettingsModification() {
35 val project = ProjectManager.getInstance().defaultProject
36 val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
37 val profile = profileManager.getProfile(LightPlatformTestCase.PROFILE) as InspectionProfileImpl
38 profile.initInspectionTools(project)
40 val model = profile.modifiableModel
41 val panel = SingleInspectionProfilePanel(profileManager, LightPlatformTestCase.PROFILE, model, profile)
42 panel.isVisible = true
45 val tool = getInspection(model)
46 TestCase.assertEquals("", tool.myAdditionalJavadocTags)
47 tool.myAdditionalJavadocTags = "foo"
48 model.setModified(true)
50 TestCase.assertEquals(1, InspectionProfileTest.countInitializedTools(model))
52 TestCase.assertEquals("foo", getInspection(profile).myAdditionalJavadocTags)
56 fun testModifyInstantiatedTool() {
57 val project = ProjectManager.getInstance().defaultProject
58 val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
59 val profile = profileManager.getProfile(LightPlatformTestCase.PROFILE) as InspectionProfileImpl
60 profile.initInspectionTools(project)
62 val originalTool = getInspection(profile)
63 originalTool.myAdditionalJavadocTags = "foo"
65 val model = profile.modifiableModel
67 val panel = SingleInspectionProfilePanel(profileManager, LightPlatformTestCase.PROFILE, model, profile)
68 panel.isVisible = true
70 TestCase.assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1,
71 InspectionProfileTest.countInitializedTools(model))
73 val copyTool = getInspection(model)
74 copyTool.myAdditionalJavadocTags = "bar"
76 model.setModified(true)
78 TestCase.assertEquals(1, InspectionProfileTest.countInitializedTools(model))
80 TestCase.assertEquals("bar", getInspection(profile).myAdditionalJavadocTags)
84 fun testDoNotChangeSettingsOnCancel() {
85 val project = ProjectManager.getInstance().defaultProject
86 val profileManager = InspectionProjectProfileManager.getInstance(project)
87 val profile = profileManager.getProfile(LightPlatformTestCase.PROFILE) as InspectionProfileImpl
88 profile.initInspectionTools(project)
90 val originalTool = getInspection(profile)
91 TestCase.assertEquals("", originalTool.myAdditionalJavadocTags)
93 val model = profile.modifiableModel
94 val copyTool = getInspection(model)
95 copyTool.myAdditionalJavadocTags = "foo"
96 // this change IS NOT COMMITTED
98 TestCase.assertEquals("", getInspection(profile).myAdditionalJavadocTags)
101 private fun getInspection(profile: InspectionProfileImpl): JavaDocLocalInspection {
102 val original = (profile.getInspectionTool(myInspection.shortName, LightPlatformTestCase.getProject()) as LocalInspectionToolWrapper?)!!
103 return original.tool as JavaDocLocalInspection
106 override fun setUp() {
107 InspectionProfileImpl.INIT_INSPECTIONS = true
111 override fun tearDown() {
112 InspectionProfileImpl.INIT_INSPECTIONS = false
116 override fun configureLocalInspectionTools() = arrayOf(myInspection)