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.ProjectInspectionProfileManager
24 import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel
25 import com.intellij.testFramework.LightIdeaTestCase
26 import com.intellij.testFramework.configureInspections
27 import com.intellij.testFramework.createProfile
28 import junit.framework.TestCase
29 import org.assertj.core.api.Assertions.assertThat
31 class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
32 private val myInspection = JavaDocLocalInspection()
35 fun testSettingsModification() {
36 val project = ProjectManager.getInstance().defaultProject
37 val profile = configureInspections(arrayOf(myInspection), project, myTestRootDisposable)
39 val model = profile.modifiableModel
40 val panel = SingleInspectionProfilePanel(ProjectInspectionProfileManager.getInstanceImpl(project), profile.name, model, profile)
41 panel.isVisible = true
44 val tool = getInspection(model)
45 assertEquals("", tool.myAdditionalJavadocTags)
46 tool.myAdditionalJavadocTags = "foo"
47 model.setModified(true)
49 assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1)
51 assertThat(getInspection(profile).myAdditionalJavadocTags).isEqualTo("foo")
55 fun testModifyInstantiatedTool() {
56 val project = ProjectManager.getInstance().defaultProject
57 val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
58 val profile = profileManager.createProfile(myInspection, myTestRootDisposable)
59 profile.initInspectionTools(project)
61 val originalTool = getInspection(profile)
62 originalTool.myAdditionalJavadocTags = "foo"
64 val model = profile.modifiableModel
66 val panel = SingleInspectionProfilePanel(profileManager, profile.name, model, profile)
67 panel.isVisible = true
69 TestCase.assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1,
70 InspectionProfileTest.countInitializedTools(model))
72 val copyTool = getInspection(model)
73 copyTool.myAdditionalJavadocTags = "bar"
75 model.setModified(true)
77 assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1)
79 assertEquals("bar", getInspection(profile).myAdditionalJavadocTags)
83 fun testDoNotChangeSettingsOnCancel() {
84 val project = ProjectManager.getInstance().defaultProject
85 val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
86 val profile = profileManager.createProfile(myInspection, myTestRootDisposable)
87 profile.initInspectionTools(project)
89 val originalTool = getInspection(profile)
90 assertThat(originalTool.myAdditionalJavadocTags).isEmpty()
92 val model = profile.modifiableModel
93 val copyTool = getInspection(model)
94 copyTool.myAdditionalJavadocTags = "foo"
95 // this change IS NOT COMMITTED
97 assertEquals("", getInspection(profile).myAdditionalJavadocTags)
100 private fun getInspection(profile: InspectionProfileImpl): JavaDocLocalInspection {
101 return (profile.getInspectionTool(myInspection.shortName, getProject()) as LocalInspectionToolWrapper?)!!.tool as JavaDocLocalInspection
104 override fun setUp() {
105 InspectionProfileImpl.INIT_INSPECTIONS = true
109 override fun tearDown() {
110 InspectionProfileImpl.INIT_INSPECTIONS = false
114 override fun configureLocalInspectionTools() = arrayOf(myInspection)