diff options
Diffstat (limited to 'java/java-tests/testSrc/com/intellij/codeInspection')
6 files changed, 199 insertions, 180 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java deleted file mode 100644 index 600b822e2780..000000000000 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInspection; - -import com.intellij.JavaTestUtil; -import com.intellij.codeInsight.NullableNotNullManager; -import com.intellij.codeInspection.dataFlow.DataFlowInspection; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.util.Disposer; -import com.intellij.pom.java.LanguageLevel; -import com.intellij.testFramework.builders.JavaModuleFixtureBuilder; -import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; - -/** - * @author peter - */ -public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCase { - @Override - protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) { - moduleBuilder.setLanguageLevel(LanguageLevel.HIGHEST); - } - - @Override - protected String getTestDataPath() { - return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/"; - } - - private void doTest() { - final DataFlowInspection inspection = new DataFlowInspection(); - inspection.SUGGEST_NULLABLE_ANNOTATIONS = true; - myFixture.enableInspections(inspection); - myFixture.testHighlighting(true, false, true, getTestName(false) + ".java"); - } - - public void testTryInAnonymous() throws Throwable { doTest(); } - public void testNullableAnonymousMethod() throws Throwable { doTest(); } - public void testNullableAnonymousParameter() throws Throwable { doTest(); } - public void testNullableAnonymousVolatile() throws Throwable { doTest(); } - public void testNullableAnonymousVolatileNotNull() throws Throwable { doTest(); } - public void testLocalClass() throws Throwable { doTest(); } - - public void testFieldInAnonymous() throws Throwable { doTest(); } - public void testFieldInitializerInAnonymous() throws Throwable { doTest(); } - public void testNullableField() throws Throwable { doTest(); } - public void testCanBeNullDoesntImplyIsNull() throws Throwable { doTest(); } - public void testAnnReport() throws Throwable { doTest(); } - - public void testBigMethodNotComplex() throws Throwable { doTest(); } - public void testBuildRegexpNotComplex() throws Throwable { doTest(); } - public void testTernaryInWhileNotComplex() throws Throwable { doTest(); } - public void testTryCatchInForNotComplex() throws Throwable { doTest(); } - public void testFieldChangedBetweenSynchronizedBlocks() throws Throwable { doTest(); } - - public void testGeneratedEquals() throws Throwable { doTest(); } - - public void testIDEA84489() throws Throwable { doTest(); } - public void testComparingToNotNullShouldNotAffectNullity() throws Throwable { doTest(); } - public void testStringTernaryAlwaysTrue() throws Throwable { doTest(); } - - public void testBoxing128() throws Throwable { doTest(); } - public void testFinalFieldsInitializedByAnnotatedParameters() throws Throwable { doTest(); } - public void testMultiCatch() throws Throwable { doTest(); } - public void testContinueFlushesLoopVariable() throws Throwable { doTest(); } - - public void testEqualsNotNull() throws Throwable { doTest(); } - public void testVisitFinallyOnce() throws Throwable { doTest(); } - public void testNotEqualsDoesntImplyNotNullity() throws Throwable { doTest(); } - public void testEqualsEnumConstant() throws Throwable { doTest(); } - public void testEqualsConstant() throws Throwable { doTest(); } - public void testFinalLoopVariableInstanceof() throws Throwable { doTest(); } - public void testGreaterIsNotEquals() throws Throwable { doTest(); } - public void testNotGreaterIsNotEquals() throws Throwable { doTest(); } - - public void testChainedFinalFieldsDfa() throws Throwable { doTest(); } - public void testFinalFieldsDifferentInstances() throws Throwable { doTest(); } - public void testThisFieldGetters() throws Throwable { doTest(); } - public void testChainedFinalFieldAccessorsDfa() throws Throwable { doTest(); } - - public void testAssigningUnknownToNullable() throws Throwable { doTest(); } - public void testAssigningClassLiteralToNullable() throws Throwable { doTest(); } - - public void testSynchronizingOnNullable() throws Throwable { doTest(); } - public void testReturningNullFromVoidMethod() throws Throwable { doTest(); } - - public void testCatchRuntimeException() throws Throwable { doTest(); } - - public void testAssertFailInCatch() throws Throwable { - myFixture.addClass("package org.junit; public class Assert { public static void fail() {}}"); - doTest(); - } - - public void testPreserveNullableOnUncheckedCast() throws Throwable { doTest(); } - - public void testPassingNullableIntoVararg() throws Throwable { doTest(); } - public void testEqualsImpliesNotNull() throws Throwable { doTest(); } - - public void testAnnotatedTypeParameters() throws Throwable { - setupCustomAnnotations(); - doTest(); - } - - private void setupCustomAnnotations() { - myFixture.addClass("package foo; public @interface Nullable {}"); - myFixture.addClass("package foo; public @interface NotNull {}"); - final NullableNotNullManager nnnManager = NullableNotNullManager.getInstance(getProject()); - nnnManager.setNotNulls("foo.NotNull"); - nnnManager.setNullables("foo.Nullable"); - Disposer.register(myTestRootDisposable, new Disposable() { - @Override - public void dispose() { - nnnManager.setNotNulls(); - nnnManager.setNullables(); - } - }); - } - - public void testSkipAssertions() { - final DataFlowInspection inspection = new DataFlowInspection(); - inspection.DONT_REPORT_TRUE_ASSERT_STATEMENTS = true; - myFixture.enableInspections(inspection); - myFixture.testHighlighting(true, false, true, getTestName(false) + ".java"); - } - - public void testCheckFieldInitializers() { - doTest(); - } - - public void testConstantDoubleComparisons() { doTest(); } - - public void _testMutableNullableFieldsTreatment() { doTest(); } - public void _testMutableVolatileNullableFieldsTreatment() { doTest(); } - public void testMutableNotAnnotatedFieldsTreatment() { doTest(); } - - public void testMethodCallFlushesField() { doTest(); } - public void testUnknownFloatMayBeNaN() { doTest(); } - public void testLastConstantConditionInAnd() { doTest(); } - - public void testTransientFinalField() { doTest(); } - public void _testSymmetricUncheckedCast() { doTest(); } - public void testNullCheckDoesntAffectUncheckedCast() { doTest(); } - - public void testNullableForeachVariable() { - setupCustomAnnotations(); - doTest(); - } - -} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index 480d955128bc..56fa8115d95f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -15,22 +15,147 @@ */ package com.intellij.codeInspection; -import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; +import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.NullableNotNullManager; import com.intellij.codeInspection.dataFlow.DataFlowInspection; -import org.jetbrains.annotations.NonNls; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.util.Disposer; +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -public class DataFlowInspectionTest extends LightDaemonAnalyzerTestCase { - @NonNls static final String BASE_PATH = "/inspection/dataFlow"; +/** + * @author peter + */ +public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { + + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/"; + } private void doTest() { - doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false); + final DataFlowInspection inspection = new DataFlowInspection(); + inspection.SUGGEST_NULLABLE_ANNOTATIONS = true; + myFixture.enableInspections(inspection); + myFixture.testHighlighting(true, false, true, getTestName(false) + ".java"); } - @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{new DataFlowInspection()}; + public void testTryInAnonymous() throws Throwable { doTest(); } + public void testNullableAnonymousMethod() throws Throwable { doTest(); } + public void testNullableAnonymousParameter() throws Throwable { doTest(); } + public void testNullableAnonymousVolatile() throws Throwable { doTest(); } + public void testNullableAnonymousVolatileNotNull() throws Throwable { doTest(); } + public void testLocalClass() throws Throwable { doTest(); } + + public void testFieldInAnonymous() throws Throwable { doTest(); } + public void testFieldInitializerInAnonymous() throws Throwable { doTest(); } + public void testNullableField() throws Throwable { doTest(); } + public void testCanBeNullDoesntImplyIsNull() throws Throwable { doTest(); } + public void testAnnReport() throws Throwable { doTest(); } + + public void testBigMethodNotComplex() throws Throwable { doTest(); } + public void testBuildRegexpNotComplex() throws Throwable { doTest(); } + public void testTernaryInWhileNotComplex() throws Throwable { doTest(); } + public void testTryCatchInForNotComplex() throws Throwable { doTest(); } + public void testFieldChangedBetweenSynchronizedBlocks() throws Throwable { doTest(); } + + public void testGeneratedEquals() throws Throwable { doTest(); } + + public void testIDEA84489() throws Throwable { doTest(); } + public void testComparingToNotNullShouldNotAffectNullity() throws Throwable { doTest(); } + public void testStringTernaryAlwaysTrue() throws Throwable { doTest(); } + + public void testBoxing128() throws Throwable { doTest(); } + public void testFinalFieldsInitializedByAnnotatedParameters() throws Throwable { doTest(); } + public void testMultiCatch() throws Throwable { doTest(); } + public void testContinueFlushesLoopVariable() throws Throwable { doTest(); } + + public void testEqualsNotNull() throws Throwable { doTest(); } + public void testVisitFinallyOnce() throws Throwable { doTest(); } + public void testNotEqualsDoesntImplyNotNullity() throws Throwable { doTest(); } + public void testEqualsEnumConstant() throws Throwable { doTest(); } + public void testEqualsConstant() throws Throwable { doTest(); } + public void testFinalLoopVariableInstanceof() throws Throwable { doTest(); } + public void testGreaterIsNotEquals() throws Throwable { doTest(); } + public void testNotGreaterIsNotEquals() throws Throwable { doTest(); } + + public void testChainedFinalFieldsDfa() throws Throwable { doTest(); } + public void testFinalFieldsDifferentInstances() throws Throwable { doTest(); } + public void testThisFieldGetters() throws Throwable { doTest(); } + public void testChainedFinalFieldAccessorsDfa() throws Throwable { doTest(); } + + public void testAssigningUnknownToNullable() throws Throwable { doTest(); } + public void testAssigningClassLiteralToNullable() throws Throwable { doTest(); } + + public void testSynchronizingOnNullable() throws Throwable { doTest(); } + public void testReturningNullFromVoidMethod() throws Throwable { doTest(); } + + public void testCatchRuntimeException() throws Throwable { doTest(); } + + public void testAssertFailInCatch() throws Throwable { + myFixture.addClass("package org.junit; public class Assert { public static void fail() {}}"); + doTest(); + } + + public void testPreserveNullableOnUncheckedCast() throws Throwable { doTest(); } + + public void testPassingNullableIntoVararg() throws Throwable { doTest(); } + public void testEqualsImpliesNotNull() throws Throwable { doTest(); } + public void testEffectivelyUnqualified() throws Throwable { doTest(); } + + public void testAnnotatedTypeParameters() throws Throwable { + setupCustomAnnotations(); + doTest(); + } + + private void setupCustomAnnotations() { + myFixture.addClass("package foo; public @interface Nullable {}"); + myFixture.addClass("package foo; public @interface NotNull {}"); + final NullableNotNullManager nnnManager = NullableNotNullManager.getInstance(getProject()); + nnnManager.setNotNulls("foo.NotNull"); + nnnManager.setNullables("foo.Nullable"); + Disposer.register(myTestRootDisposable, new Disposable() { + @Override + public void dispose() { + nnnManager.setNotNulls(); + nnnManager.setNullables(); + } + }); + } + + public void testSkipAssertions() { + final DataFlowInspection inspection = new DataFlowInspection(); + inspection.DONT_REPORT_TRUE_ASSERT_STATEMENTS = true; + myFixture.enableInspections(inspection); + myFixture.testHighlighting(true, false, true, getTestName(false) + ".java"); + } + + public void testCheckFieldInitializers() { + doTest(); + } + + public void testConstantDoubleComparisons() { doTest(); } + + public void testMutableNullableFieldsTreatment() { doTest(); } + public void testMutableVolatileNullableFieldsTreatment() { doTest(); } + public void testMutableNotAnnotatedFieldsTreatment() { doTest(); } + + public void testMethodCallFlushesField() { doTest(); } + public void testUnknownFloatMayBeNaN() { doTest(); } + public void testLastConstantConditionInAnd() { doTest(); } + + public void testTransientFinalField() { doTest(); } + public void _testSymmetricUncheckedCast() { doTest(); } + public void testNullCheckDoesntAffectUncheckedCast() { doTest(); } + + public void testNullableForeachVariable() { + setupCustomAnnotations(); + doTest(); } public void testTryWithResourcesNullability() { doTest(); } public void testTryWithResourcesInstanceOf() { doTest(); } + public void testOmnipresentExceptions() { doTest(); } + + public void testEqualsHasNoSideEffects() { doTest(); } + } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java index 07d2bf4fc99e..480a910cc394 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java @@ -23,7 +23,6 @@ public class DataFlowInspectionTestSuite { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(DataFlowInspectionTest.class); - suite.addTestSuite(DataFlowInspectionFixtureTest.class); suite.addTestSuite(DataFlowInspectionAncientTest.class); suite.addTestSuite(SliceTreeTest.class); return suite; diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java index dab2baf370b2..872ae1277119 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java @@ -21,7 +21,6 @@ import com.intellij.codeInsight.CodeInsightTestCase; import com.intellij.codeInspection.actions.RunInspectionIntention; import com.intellij.codeInspection.ex.*; import com.intellij.codeInspection.visibility.VisibilityInspection; -import com.intellij.profile.codeInspection.InspectionProfileManager; import java.util.ArrayList; import java.util.Arrays; @@ -56,7 +55,7 @@ public class GlobalInspectionContextTest extends CodeInsightTestCase { } public void testRunInspectionContext() throws Exception { - InspectionProfile profile = (InspectionProfile)InspectionProfileManager.getInstance().getRootProfile(); + InspectionProfile profile = new InspectionProfileImpl("foo"); InspectionProfileEntry[] tools = profile.getInspectionTools(null); for (InspectionProfileEntry tool : tools) { if (!tool.isEnabledByDefault()) { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java index 409426b19c0b..b8ad3a04614d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java @@ -16,6 +16,7 @@ package com.intellij.codeInspection; import com.intellij.codeInsight.daemon.HighlightDisplayKey; +import com.intellij.codeInspection.dataFlow.DataFlowInspection; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.ex.*; import com.intellij.openapi.util.JDOMUtil; @@ -254,7 +255,8 @@ public class InspectionProfileTest extends LightIdeaTestCase { assertEquals(0, countInitializedTools(profile)); InspectionProfileEntry[] tools = profile.getInspectionTools(null); assertTrue(tools.length > 0); - InspectionProfileEntry tool = tools[0]; + InspectionProfileEntry tool = profile.getInspectionTool(new DataFlowInspection().getShortName()); + assertNotNull(tool); String id = tool.getShortName(); System.out.println(id); if (profile.isToolEnabled(HighlightDisplayKey.findById(id))) { @@ -263,9 +265,15 @@ public class InspectionProfileTest extends LightIdeaTestCase { else { profile.enableTool(id); } + assertEquals(0, countInitializedTools(profile)); profile.writeExternal(new Element("profile")); List<InspectionProfileEntry> initializedTools = getInitializedTools(profile); - assertEquals(initializedTools.toString(), 1, initializedTools.size()); + if (initializedTools.size() != 1) { + for (InspectionProfileEntry initializedTool : initializedTools) { + System.out.println(initializedTool.getShortName()); + } + fail(); + } } public void testInspectionInitializationForSerialization() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java index 01d2908f7c0c..ab3a853a96bb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java @@ -23,6 +23,7 @@ import com.intellij.openapi.project.ProjectManager; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel; import com.intellij.testFramework.LightIdeaTestCase; +import org.jetbrains.annotations.NotNull; /** * @author Dmitry Avdeev @@ -46,19 +47,65 @@ public class SingleInspectionProfilePanelTest extends LightIdeaTestCase { panel.reset(); assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 0, InspectionProfileTest.countInitializedTools(model)); - LocalInspectionToolWrapper wrapper = (LocalInspectionToolWrapper)model.getInspectionTool(myInspection.getShortName()); - assert wrapper != null; - JavaDocLocalInspection tool = (JavaDocLocalInspection)wrapper.getTool(); + JavaDocLocalInspection tool = getInspection(model); assertEquals("", tool.myAdditionalJavadocTags); tool.myAdditionalJavadocTags = "foo"; model.setModified(true); panel.apply(); assertEquals(1, InspectionProfileTest.countInitializedTools(model)); - wrapper = (LocalInspectionToolWrapper)profile.getInspectionTool(myInspection.getShortName()); - assert wrapper != null; - tool = (JavaDocLocalInspection)wrapper.getTool(); - assertEquals("foo", tool.myAdditionalJavadocTags); + assertEquals("foo", getInspection(profile).myAdditionalJavadocTags); + } + + public void testModifyInstantiatedTool() throws Exception { + Project project = ProjectManager.getInstance().getDefaultProject(); + InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project); + InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE); + profile.initInspectionTools(project); + assertEquals(0, InspectionProfileTest.countInitializedTools(profile)); + + JavaDocLocalInspection originalTool = getInspection(profile); + originalTool.myAdditionalJavadocTags = "foo"; + + InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel(); + + SingleInspectionProfilePanel panel = new SingleInspectionProfilePanel(profileManager, PROFILE, model); + panel.setVisible(true); + panel.reset(); + assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1, InspectionProfileTest.countInitializedTools(model)); + + JavaDocLocalInspection copyTool = getInspection(model); + copyTool.myAdditionalJavadocTags = "bar"; + + model.setModified(true); + panel.apply(); + assertEquals(1, InspectionProfileTest.countInitializedTools(model)); + + assertEquals("bar", getInspection(profile).myAdditionalJavadocTags); + } + + public void testDoNotChangeSettingsOnCancel() throws Exception { + Project project = ProjectManager.getInstance().getDefaultProject(); + InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project); + InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE); + profile.initInspectionTools(project); + assertEquals(0, InspectionProfileTest.countInitializedTools(profile)); + + JavaDocLocalInspection originalTool = getInspection(profile); + assertEquals("", originalTool.myAdditionalJavadocTags); + + InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel(); + JavaDocLocalInspection copyTool = getInspection(model); + copyTool.myAdditionalJavadocTags = "foo"; + // this change IS NOT COMMITTED + + assertEquals("", getInspection(profile).myAdditionalJavadocTags); + } + + private JavaDocLocalInspection getInspection(InspectionProfileImpl profile) { + LocalInspectionToolWrapper original = (LocalInspectionToolWrapper)profile.getInspectionTool(myInspection.getShortName()); + assert original != null; + return (JavaDocLocalInspection)original.getTool(); } @Override @@ -75,6 +122,7 @@ public class SingleInspectionProfilePanelTest extends LightIdeaTestCase { private final JavaDocLocalInspection myInspection = new JavaDocLocalInspection(); + @NotNull @Override protected LocalInspectionTool[] configureLocalInspectionTools() { return new LocalInspectionTool[] {myInspection}; |