From 02cf98d65c798d368fcec43ed64a001d513bdd4f Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Tue, 19 Aug 2014 12:53:10 -0700 Subject: Snapshot idea/138.1503 from git://git.jetbrains.org/idea/community.git Change-Id: Ie01af1d8710ec0ff51d90301bda1a18b0b5c0faf --- .../TypeMayBeWeakenedInspectionTest.java | 56 +++++++++++++++------- .../CastConflictsWithInstanceofInspectionTest.java | 4 ++ .../StringBufferReplaceableByStringFixTest.java | 1 + .../ExtendsConcreteCollectionInspectionTest.java | 2 +- .../PropertyValueSetToItselfInspectionTest.java | 56 ++++++++++++++++++++++ 5 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java (limited to 'plugins/InspectionGadgets/testsrc') diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java index fec91135e731..df0048a5218f 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspectionTest.java @@ -1,24 +1,48 @@ package com.siyeh.ig.abstraction; -import com.intellij.openapi.roots.LanguageLevelProjectExtension; -import com.intellij.pom.java.LanguageLevel; -import com.siyeh.ig.IGInspectionTestCase; +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; -public class TypeMayBeWeakenedInspectionTest extends IGInspectionTestCase { +public class TypeMayBeWeakenedInspectionTest extends LightInspectionTestCase { - public void test() throws Exception { - final TypeMayBeWeakenedInspection inspection = - new TypeMayBeWeakenedInspection(); + public void testTypeMayBeWeakened() { doTest(); } + public void testNumberAdderDemo() { doTest(); } + public void testAutoClosableTest() { doTest(); } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package weaken_type.sub;\n" + + "public class NumberAdderImpl implements NumberAdder {\n" + + " public int doSomething() {\n" + + " return getNumberOne() + 1;\n" + + " }\n" + + " protected int getNumberOne() {\n" + + " return 1;\n" + + " }\n" + + "}", + "package weaken_type.sub;\n" + + "public class NumberAdderExtension extends NumberAdderImpl {\n" + + " @Override\n" + + " public int getNumberOne() {\n" + + " return super.getNumberOne();\n" + + " }\n" + + "}" + }; + } + + @Override + protected String getBasePath() { + return "/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type"; + } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + final TypeMayBeWeakenedInspection inspection = new TypeMayBeWeakenedInspection(); inspection.doNotWeakenToJavaLangObject = false; inspection.onlyWeakentoInterface = false; - final LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject()); - final LanguageLevel level = levelProjectExtension.getLanguageLevel(); - try { - levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_7); - doTest("com/siyeh/igtest/abstraction/weaken_type", inspection); - } - finally { - levelProjectExtension.setLanguageLevel(level); - } + return inspection; } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java index ff6d488a6fd9..079bda6ac35f 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java @@ -43,6 +43,10 @@ public class CastConflictsWithInstanceofInspectionTest extends IGInspectionTestC doTest(); } + public void testOrInstanceofOrInstanceof() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest("com/siyeh/igtest/bugs/castConflictingInstanceof/" + getTestName(true), new CastConflictsWithInstanceofInspection()); } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java index f49e16b89c4a..8c7920b9567d 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/style/StringBufferReplaceableByStringFixTest.java @@ -32,4 +32,5 @@ public class StringBufferReplaceableByStringFixTest extends IGQuickFixesTestCase public void testCharLiteral() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); } public void testEscape() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); } public void testUnescape() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); } + public void testMethodCallOnString() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); } } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java index 99c6a2480928..a2b334c2661c 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/ExtendsConcreteCollectionInspectionTest.java @@ -31,7 +31,7 @@ public class ExtendsConcreteCollectionInspectionTest extends LightInspectionTest protected String[] getEnvironmentClasses() { return new String[] { "package java.util;" + - "public class LinkedHashMap {" + + "public class LinkedHashMap extends HashMap implements Map{" + " protected boolean removeEldestEntry(Map.Entry eldest) {\n" + " return false;\n" + " }" + diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java new file mode 100644 index 000000000000..d17387119ae1 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/javabeans/PropertyValueSetToItselfInspectionTest.java @@ -0,0 +1,56 @@ +/* + * 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.javabeans; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +public class PropertyValueSetToItselfInspectionTest extends LightInspectionTestCase { + + public void testSimple() { + doTest("class Bean {\n" + + " private String x;\n" + + " public void setX(String x) {\n" + + " this.x = x;\n" + + " }\n" + + " public String getX() { return x; }\n" + + " void m(Bean b) {\n" + + " (b)./*Property value set to itself*/setX/**/(b.getX());\n" + + " this./*Property value set to itself*/setX/**/(getX());\n" + + " }\n" + + "}"); + } + + public void testNoWarn() { + doTest("class Bean {\n" + + " private String x;\n" + + " public void setX(String x) {\n" + + " this.x = x;\n" + + " }\n" + + " public String getX() { return x; }\n" + + " void m(Bean b, Bean c) {\n" + + " (b).setX(c.getX());\n" + + " }\n" + + "}"); + } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new PropertyValueSetToItselfInspection(); + } +} \ No newline at end of file -- cgit v1.2.3