IG: check for TestCase too
authorBas Leijdekkers <basleijdekkers@gmail.com>
Mon, 10 Oct 2016 12:48:36 +0000 (14:48 +0200)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Mon, 10 Oct 2016 15:28:57 +0000 (17:28 +0200)
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java
plugins/InspectionGadgets/test/com/siyeh/igtest/junit/use_of_obsolete_assert/ObsoleteAssert.java
plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/UseOfObsoleteAssertInspectionTest.java

index 9c0fc63d5657613c722ab55a3bae3c19dbc6b595..b64cefa9fabcbc50eb6d2ac49017c94fbc03f610 100644 (file)
@@ -1906,8 +1906,8 @@ static.variable.of.concrete.class.option=Ignore static fields whose type is an a
 class.only.used.in.one.package.display.name=Class only used from one other package
 class.only.used.in.one.package.problem.descriptor=Class <code>#ref</code> has only dependencies on and/or dependents in package ''{0}'' #loc
 unnecessary.return.option=Ignore in then branch of 'if' statement with 'else' branch
-usage.of.obsolete.assert.display.name=Usage of obsolete 'junit.framework.Assert'
-use.of.obsolete.assert.problem.descriptor=Call to <code>#ref()</code> from 'junit.framework.Assert' should be replaced with call to method from 'org.junit.Assert' #loc
+usage.of.obsolete.assert.display.name=Usage of obsolete 'junit.framework.Assert' method
+use.of.obsolete.assert.problem.descriptor=Call to <code>#ref()</code> from ''{0}'' should be replaced with call to method from ''org.junit.Assert'' #loc
 use.of.obsolete.assert.quickfix=Replace with 'org.junit.Assert' method call
 properties.object.as.hashtable.set.quickfix=Replace with call to 'setProperty()'
 properties.object.as.hashtable.get.quickfix=Replace with call to 'getProperty()'
index 4fb48ba885f997e5d120b40c872190e474ee1c90..e64db5b5e56f9c87e4325e99f2a0af4550701e27 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2016 Dave Griffith, Bas Leijdekkers
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,7 +43,8 @@ public class UseOfObsoleteAssertInspection extends BaseInspection {
   @Override
   @NotNull
   protected String buildErrorString(Object... infos) {
-    return InspectionGadgetsBundle.message("use.of.obsolete.assert.problem.descriptor");
+    String name = (String)infos[0];
+    return InspectionGadgetsBundle.message("use.of.obsolete.assert.problem.descriptor", name);
   }
 
   @Override
@@ -75,8 +76,12 @@ public class UseOfObsoleteAssertInspection extends BaseInspection {
         return;
       }
       final PsiClass containingClass = psiMethod.getContainingClass();
-      if (containingClass != null && Comparing.strEqual(containingClass.getQualifiedName(), "junit.framework.Assert")) {
-        registerMethodCallError(expression);
+      if (containingClass == null) {
+        return;
+      }
+      final String name = containingClass.getQualifiedName();
+      if ("junit.framework.Assert".equals(name) || "junit.framework.TestCase".equals(name)) {
+        registerMethodCallError(expression, name);
       }
     }
   }
index 4087eb8d7bbfc2f76cbc0c5a555da7fa75776457..d49dde6177da73036e456057a9d86637ed514ada 100644 (file)
@@ -4,5 +4,6 @@ public class ObsoleteAssert {
 
   public void testMe(int s) {
     junit.framework.Assert.<warning descr="Call to 'assertEquals()' from 'junit.framework.Assert' should be replaced with call to method from 'org.junit.Assert'">assertEquals</warning>("asdfasd", -1, s);
+    junit.framework.TestCase.<warning descr="Call to 'assertEquals()' from 'junit.framework.TestCase' should be replaced with call to method from 'org.junit.Assert'">assertEquals</warning>("asdfasd", -1, s);
   }
 }
index 19826e2c091eb1ea4674039864e9442ba9eec0a3..b58351e77285a27f37ea5dd1786f89535e746a03 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -32,6 +32,14 @@ public class UseOfObsoleteAssertInspectionTest extends LightInspectionTestCase {
       "public class Assert {" +
       "  static public void assertEquals(String message, int expected, int actual) {}" +
       "}",
+
+      "package junit.framework;" +
+      "public class TestCase extends Assert {" +
+      "  public static void assertEquals(String message, int expected, int actual) {" +
+      "    Assert.assertEquals(message, expected, actual);" +
+      "  }" +
+      "}",
+
       "package org.junit;" +
       "public class Assert {}"
     };