replace old assert with new (IDEA-175693)

deprecated method always fail, add default delta to preserve the test state
This commit is contained in:
Anna.Kozlova
2017-12-29 12:22:14 +01:00
parent 7509a3342d
commit 8a80bb8368
4 changed files with 38 additions and 2 deletions
@@ -147,6 +147,18 @@ public class UseOfObsoleteAssertInspection extends BaseInspection {
styleManager.shortenClassReferences(methodExpression);
}
}
PsiMethod newTarget = methodCallExpression.resolveMethod();
if (newTarget != null && newTarget.isDeprecated()) {
PsiParameter[] parameters = newTarget.getParameterList().getParameters();
if (parameters.length > 0) {
PsiType paramType = parameters[parameters.length - 1].getType();
if (PsiType.DOUBLE.equals(paramType) || PsiType.FLOAT.equals(paramType)) {
methodCallExpression.getArgumentList().add(JavaPsiFacade.getElementFactory(project).createExpressionFromText("0.0", methodCallExpression));
}
}
}
/*
//refs can be optimized now but should we really?
if (isImportUnused) {
@@ -0,0 +1,7 @@
import static org.junit.Assert.assertEquals;
class MyTest {
public void test() {
assertEquals(1.0, 1.0, 0.0);
}
}
@@ -0,0 +1,7 @@
import static junit.framework.Assert.assertEquals;
class MyTest {
public void test() {
assert<caret>Equals(1.0, 1.0);
}
}
@@ -24,10 +24,16 @@ public class UseOfObsoleteAssertInspectionTest extends IGQuickFixesTestCase {
public void setUp() throws Exception {
super.setUp();
myFixture.addClass("package junit.framework; public class Assert { public static void fail(){}}");
myFixture.addClass("package junit.framework; public class Assert { public static void fail(){}" +
"public static void assertEquals(double d1, double d2, double d3) {}" +
"public static void assertEquals(Object o1, Object o2) {}" +
"}");
myFixture.addClass("package junit.framework; public class TestCase extends Assert {}");
myFixture.addClass("package org.junit; public class Assert { public static void fail(){}}");
myFixture.addClass("package org.junit; public class Assert { " +
"public static void fail(){}" +
"@Deprecated public static void assertEquals(double d1, double d2) {}" +
" public static void assertEquals(double d1, double d2, double d3) {}}");
myFixture.enableInspections(new UseOfObsoleteAssertInspection());
}
@@ -56,6 +62,10 @@ public class UseOfObsoleteAssertInspectionTest extends IGQuickFixesTestCase {
doFixTest();
}
public void testAddingDeltaToAvoidFailure() {
doFixTest();
}
private void doFixTest() {
doTest(getTestName(true), InspectionGadgetsBundle.message("use.of.obsolete.assert.quickfix"));
}