diff options
Diffstat (limited to 'plugins/InspectionGadgets/testsrc/com')
13 files changed, 333 insertions, 16 deletions
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java index d262e31333ba..951d14ad9f8b 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java @@ -109,15 +109,20 @@ public abstract class LightInspectionTestCase extends LightCodeInsightFixtureTes lastWord = lastWord.substring(0, lastWord.length() - 10); } final int length = lastWord.length(); + boolean upperCase = false; for (int i = 0; i < length; i++) { final char ch = lastWord.charAt(i); if (Character.isUpperCase(ch)) { - if (i != 0) { - basePath.append('_'); + if (!upperCase) { + upperCase = true; + if (i != 0) { + basePath.append('_'); + } } basePath.append(Character.toLowerCase(ch)); } else { + upperCase = false; basePath.append(ch); } } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsWithItselfInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsWithItselfInspectionTest.java new file mode 100644 index 000000000000..868884ffa6db --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsWithItselfInspectionTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2014 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.siyeh.ig.bugs; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class EqualsWithItselfInspectionTest extends LightInspectionTestCase { + + public void testEqualsWithItself() { doTest(); } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new EqualsWithItselfInspection(); + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/abstraction/TypeMayBeWeakenedFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/abstraction/TypeMayBeWeakenedFixTest.java index 58373f3a3955..d4b9ec3039bb 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/abstraction/TypeMayBeWeakenedFixTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/abstraction/TypeMayBeWeakenedFixTest.java @@ -12,10 +12,13 @@ public class TypeMayBeWeakenedFixTest extends IGQuickFixesTestCase { @Override public void setUp() throws Exception { super.setUp(); - myFixture.enableInspections(new TypeMayBeWeakenedInspection()); + final TypeMayBeWeakenedInspection inspection = new TypeMayBeWeakenedInspection(); + inspection.onlyWeakentoInterface = false; + myFixture.enableInspections(inspection); myRelativePath = "abstraction/type_may_be_weakened"; } public void testShorten() { doTest(InspectionGadgetsBundle.message("type.may.be.weakened.quickfix", "java.util.Collection")); } + public void testLocalClass() { doTest(InspectionGadgetsBundle.message("type.may.be.weakened.quickfix", "A")); } } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit3MethodNamingConventionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit3MethodNamingConventionInspectionTest.java new file mode 100644 index 000000000000..d71792bcbbc9 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit3MethodNamingConventionInspectionTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2014 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.siyeh.ig.junit; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class JUnit3MethodNamingConventionInspectionTest extends LightInspectionTestCase { + + public void testJUnit3MethodNamingConvention() { doTest(); } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new JUnit3MethodNamingConventionInspection(); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package junit.framework;" + + "public abstract class TestCase {" + + " protected void setUp() throws Exception {}" + + " protected void tearDown() throws Exception {}" + + "}" + }; + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit3StyleTestMethodInJUnit4ClassInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit3StyleTestMethodInJUnit4ClassInspectionTest.java new file mode 100644 index 000000000000..eb7e979f81e1 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit3StyleTestMethodInJUnit4ClassInspectionTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2014 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.siyeh.ig.junit; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class JUnit3StyleTestMethodInJUnit4ClassInspectionTest extends LightInspectionTestCase { + + public void testJUnit3StyleTestMethodInJUnit4Class() { doTest(); } + public void testBeforeAnnotationUsed() { doTest(); } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new JUnit3StyleTestMethodInJUnit4ClassInspection(); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package org.junit;" + + "import java.lang.annotation.ElementType;" + + "import java.lang.annotation.Retention;" + + "import java.lang.annotation.RetentionPolicy;" + + "import java.lang.annotation.Target;" + + "@Retention(RetentionPolicy.RUNTIME)" + + "@Target({ElementType.METHOD})" + + "public @interface Before {}", + "package org.junit;" + + "import java.lang.annotation.ElementType;" + + "import java.lang.annotation.Retention;" + + "import java.lang.annotation.RetentionPolicy;" + + "import java.lang.annotation.Target;" + + "@Retention(RetentionPolicy.RUNTIME)" + + "@Target({ElementType.METHOD})" + + "public @interface Test {}" + }; + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit4MethodNamingConventionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit4MethodNamingConventionInspectionTest.java new file mode 100644 index 000000000000..bff20e9bd24a --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/JUnit4MethodNamingConventionInspectionTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2014 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.siyeh.ig.junit; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class JUnit4MethodNamingConventionInspectionTest extends LightInspectionTestCase { + + public void testJUnit4MethodNamingConvention() { doTest(); } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new JUnit4MethodNamingConventionInspection(); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package org.junit;" + + "import java.lang.annotation.ElementType;" + + "import java.lang.annotation.Retention;" + + "import java.lang.annotation.RetentionPolicy;" + + "import java.lang.annotation.Target;" + + "@Retention(RetentionPolicy.RUNTIME)" + + "@Target({ElementType.METHOD})" + + "public @interface Test {}" + }; + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestCaseWithNoTestMethodsInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestCaseWithNoTestMethodsInspectionTest.java new file mode 100644 index 000000000000..e8566eacdcd0 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestCaseWithNoTestMethodsInspectionTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2014 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.siyeh.ig.junit; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class TestCaseWithNoTestMethodsInspectionTest extends LightInspectionTestCase { + + public void testTestCaseWithNoTestMethods() { doTest(); } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new TestCaseWithNoTestMethodsInspection(); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package junit.framework;" + + "public abstract class TestCase {" + + " protected void setUp() throws Exception {}" + + " protected void tearDown() throws Exception {}" + + "}" + }; + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestMethodIsPublicVoidNoArgInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestMethodIsPublicVoidNoArgInspectionTest.java new file mode 100644 index 000000000000..72406191f2b1 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestMethodIsPublicVoidNoArgInspectionTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 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.siyeh.ig.junit; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class TestMethodIsPublicVoidNoArgInspectionTest extends LightInspectionTestCase { + + public void testJUnit3TestMethodIsPublicVoidNoArg() { doTest(); } + public void testJUnit4TestMethodIsPublicVoidNoArg() { doTest(); } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new TestMethodIsPublicVoidNoArgInspection(); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package org.junit; " + + "public @interface Test {\n" + + " java.lang.Class<? extends java.lang.Throwable> expected() default org.junit.Test.None.class;" + + "}", + "package junit.framework;" + + "public abstract class TestCase {}"}; + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java index 9b1f2574dd77..a13e61bfd234 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java @@ -15,25 +15,36 @@ */ package com.siyeh.ig.migration; +import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.pom.java.LanguageLevel; import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.testFramework.LightProjectDescriptor; import com.siyeh.ig.IGInspectionTestCase; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class IfCanBeSwitchInspectionTest extends IGInspectionTestCase { +public class IfCanBeSwitchInspectionTest extends LightInspectionTestCase { - @Override - protected Sdk getTestProjectSdk() { - LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); - return IdeaTestUtil.getMockJdk17(); + public void testIfCanBeSwitch() throws Exception { + doTest(); } - public void test() throws Exception { + @Nullable + @Override + protected InspectionProfileEntry getInspection() { final IfCanBeSwitchInspection inspection = new IfCanBeSwitchInspection(); inspection.suggestIntSwitches = true; + inspection.suggestEnumSwitches = true; inspection.setOnlySuggestNullSafe(true); - doTest("com/siyeh/igtest/migration/if_switch", new LocalInspectionToolWrapper(inspection)); + return inspection; + } + + @Override + protected String getBasePath() { + return "/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch"; } } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/InstanceMethodNamingConventionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/InstanceMethodNamingConventionInspectionTest.java index e408509b51d5..6479236acbb3 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/InstanceMethodNamingConventionInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/InstanceMethodNamingConventionInspectionTest.java @@ -24,6 +24,14 @@ import com.siyeh.ig.LightInspectionTestCase; public class InstanceMethodNamingConventionInspectionTest extends LightInspectionTestCase { @Override + protected void setUp() throws Exception { + super.setUp(); + final NativeMethodNamingConventionInspection inspection = new NativeMethodNamingConventionInspection(); + inspection.m_minLength = 0; + myFixture.enableInspections(inspection); + } + + @Override protected InspectionProfileEntry getInspection() { return new InstanceMethodNamingConventionInspection(); } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/com/siyeh/ig/naming/OverloadedVarargsMethodInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/OverloadedVarargsMethodInspectionTest.java index 2ca586feef18..cc20bb3cc8fb 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/com/siyeh/ig/naming/OverloadedVarargsMethodInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/OverloadedVarargsMethodInspectionTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.siyeh.ig.naming.com.siyeh.ig.naming; +package com.siyeh.ig.naming; import com.intellij.codeInspection.InspectionProfileEntry; import com.siyeh.ig.LightInspectionTestCase; diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/StaticMethodNamingConventionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/StaticMethodNamingConventionInspectionTest.java index 53e2b6a37f87..5c1eb29822c9 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/StaticMethodNamingConventionInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/naming/StaticMethodNamingConventionInspectionTest.java @@ -24,6 +24,14 @@ import com.siyeh.ig.LightInspectionTestCase; public class StaticMethodNamingConventionInspectionTest extends LightInspectionTestCase { @Override + protected void setUp() throws Exception { + super.setUp(); + final NativeMethodNamingConventionInspection inspection = new NativeMethodNamingConventionInspection(); + inspection.m_minLength = 0; + myFixture.enableInspections(inspection); + } + + @Override protected InspectionProfileEntry getInspection() { return new StaticMethodNamingConventionInspection(); } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspectionTest.java index 48914c37605f..58bbf452bd9c 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspectionTest.java @@ -1,11 +1,18 @@ package com.siyeh.ig.numeric; -import com.siyeh.ig.IGInspectionTestCase; +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; -public class PointlessArithmeticExpressionInspectionTest extends IGInspectionTestCase { +public class PointlessArithmeticExpressionInspectionTest extends LightInspectionTestCase { - public void test() throws Exception { - doTest("com/siyeh/igtest/numeric/pointless_arithmetic_expression", - new PointlessArithmeticExpressionInspection()); + public void testPointlessArithmeticExpression() { + doTest(); + } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new PointlessArithmeticExpressionInspection(); } }
\ No newline at end of file |