mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace old assert with new (IDEA-175693)
deprecated method always fail, add default delta to preserve the test state
This commit is contained in:
+12
@@ -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) {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
class MyTest {
|
||||
public void test() {
|
||||
assertEquals(1.0, 1.0, 0.0);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
class MyTest {
|
||||
public void test() {
|
||||
assert<caret>Equals(1.0, 1.0);
|
||||
}
|
||||
}
|
||||
+12
-2
@@ -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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user