mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify negated assertions: don't skip the message (IDEA-216849)
GitOrigin-RevId: 6ed42ded956e238a5766d8f9931a31ba34bc5e21
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b98061a899
commit
ea1f0bc5dd
+7
-4
@@ -177,7 +177,7 @@ public abstract class SimplifiableAssertionInspection extends BaseInspection {
|
||||
replaceAssertLiteralWithAssertEquals(callExpression, position, assertTrueFalseHint.getMessage(), assertTrueFalseHint.getArgIndex(), "assertArrayEquals");
|
||||
}
|
||||
else if (BoolUtils.isNegation(position)) {
|
||||
replaceWithNegatedBooleanAssertion(callExpression, (PsiPrefixExpression) position, assertTrue ? "assertFalse" : "assertTrue");
|
||||
replaceWithNegatedBooleanAssertion(callExpression, (PsiPrefixExpression) position, assertTrue ? "assertFalse" : "assertTrue", assertTrueFalseHint.getMessage(), assertTrueFalseHint.getArgIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,14 +318,17 @@ public abstract class SimplifiableAssertionInspection extends BaseInspection {
|
||||
(PsiType.DOUBLE.equals(rhsType) && PsiType.FLOAT.equals(rhsType));
|
||||
}
|
||||
|
||||
private void replaceWithNegatedBooleanAssertion(PsiMethodCallExpression callExpression, PsiPrefixExpression expression, String newMethodName) {
|
||||
private void replaceWithNegatedBooleanAssertion(PsiMethodCallExpression callExpression,
|
||||
PsiPrefixExpression expression,
|
||||
String newMethodName,
|
||||
PsiExpression message,
|
||||
int positionIndex) {
|
||||
PsiExpression operand = PsiUtil.skipParenthesizedExprDown(expression.getOperand());
|
||||
if (operand == null) {
|
||||
return;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
addStaticImportOrQualifier(newMethodName, callExpression, builder);
|
||||
builder.append(newMethodName).append("(").append(operand.getText()).append(")");
|
||||
compoundMethodCall(callExpression, newMethodName, message, positionIndex, operand.getText(), builder);
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(callExpression, builder.toString());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ class MyTest {
|
||||
|
||||
@Test
|
||||
public void testObjectsEquals() {
|
||||
assertFalse(1 == 2);
|
||||
assertFalse("message", 1 == 2);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@ class MyTest {
|
||||
|
||||
@Test
|
||||
public void testObjectsEquals() {
|
||||
<caret>assertTrue(!(1 == 2));
|
||||
<caret>assertTrue("message", !(1 == 2));
|
||||
}
|
||||
}
|
||||
+2
@@ -72,7 +72,9 @@ public class SimplifiableJUnitAssertionFixTest extends IGQuickFixesTestCase {
|
||||
myFixture.addClass("package org.junit;" +
|
||||
"public class Assert {" +
|
||||
" public static void assertTrue(boolean condition) {}" +
|
||||
" public static void assertTrue(String message, boolean condition) {}" +
|
||||
" public static void assertFalse(boolean condition) {}" +
|
||||
" public static void assertFalse(String message, boolean condition) {}" +
|
||||
" public static void assertEquals(boolean expected, boolean actual) {}" +
|
||||
" public static void assertNotEquals(long expected, long actual) {}" +
|
||||
" public static void assertArrayEquals(int[] expected, int[] actual) {}" +
|
||||
|
||||
Reference in New Issue
Block a user