junit 5 assertions conversion: skip assertNotEquals fix for delta-methods (IDEA-163354)

This commit is contained in:
Anna.Kozlova
2016-11-07 18:56:11 +01:00
parent 761bcaf077
commit c81f48ae21
3 changed files with 28 additions and 10 deletions
@@ -109,7 +109,7 @@ public class JUnit5AssertionsConverterInspection extends BaseInspection {
String methodName = psiMethod.getName();
registerMethodCallError(expression, name,
getNewAssertClassName(methodName),
"fail".equals(methodName) && psiMethod.getParameterList().getParametersCount() == 0);
absentInJUnit5(psiMethod, methodName));
break;
}
}
@@ -117,6 +117,22 @@ public class JUnit5AssertionsConverterInspection extends BaseInspection {
}
}
private boolean absentInJUnit5(PsiMethod psiMethod, String methodName) {
if ("fail".equals(methodName)) {
return psiMethod.getParameterList().getParametersCount() == 0;
}
if ("assertNotEquals".equals(methodName)) {
PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
if (parameters.length > 0) {
int lastParamIdx = parameters[0].getType().equalsToText(CommonClassNames.JAVA_LANG_STRING) ? 3 : 2;
if (parameters.length > lastParamIdx && parameters[lastParamIdx].getType() instanceof PsiPrimitiveType) {
return true;
}
}
}
return false;
}
}
private static String getNewAssertClassName(String methodName) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 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.
@@ -13,14 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.refactoring.changeSignature;
import static org.junit.Assert.*;
/**
* User: anna
* Date: Sep 10, 2010
*/
public class MoveParameterLeftAction extends MoveParameterAction {
public MoveParameterLeftAction() {
super(true);
class Test1 {
@org.junit.jupiter.api.Test
public void test_first() throws Exception {
assertNot<caret>Equals(1, 1, 1);
}
}
@@ -26,6 +26,9 @@ public class Junit5AssertionsConverterFixTest extends IGQuickFixesTestCase {
public void testAssertArrayEqualsMessage() { doTestAssertions();}
public void testAssertEquals() { doTestAssertions();}
public void testAssertTrue() { doTestAssertions();}
public void testAssertNotEqualsWithDelta() {
assertQuickfixNotAvailable(InspectionGadgetsBundle.message("junit5.assertions.converter.quickfix", JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS));
}
public void testAssertThat() {
doTest(InspectionGadgetsBundle.message("junit5.assertions.converter.quickfix", JUnitCommonClassNames.ORG_HAMCREST_MATCHER_ASSERT));
@@ -59,6 +62,7 @@ public class Junit5AssertionsConverterFixTest extends IGQuickFixesTestCase {
" public static void assertEquals(Object expected, Object actual) {}" +
" public static void fail(String message) {}" +
" public static <T> void assertThat(String reason, T actual, org.hamcrest.Matcher<? super T> matcher) {}" +
" public static void assertNotEquals(double unexpected, double actual, double delta){}" +
"}");
myFixture.addClass("package org.junit.jupiter.api;\n" +