IDEA-113298 (replace assertTrue with assertFalse removes message)

This commit is contained in:
Bas Leijdekkers
2013-09-08 12:46:55 +02:00
parent 72c972fc46
commit 8941cf8fb5
4 changed files with 59 additions and 4 deletions
@@ -78,12 +78,13 @@ public class FlipAssertLiteralIntention extends MutablyNamedIntention {
}
newCall.append(toMethodName).append('(');
final PsiExpressionList argumentList = call.getArgumentList();
final PsiExpression[] args = argumentList.getExpressions();
if (args.length == 1) {
newCall.append(BoolUtils.getNegatedExpressionText(args[0]));
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length == 1) {
newCall.append(BoolUtils.getNegatedExpressionText(arguments[0]));
}
else {
newCall.append(BoolUtils.getNegatedExpressionText(args[1]));
newCall.append(arguments[0].getText()).append(',');
newCall.append(BoolUtils.getNegatedExpressionText(arguments[1]));
}
newCall.append(')');
replaceExpression(newCall.toString(), call);
@@ -0,0 +1,9 @@
package com.siyeh.ipp.junit.flip_assert_literal;
import org.junit.Assert;
class Messsage {
void test(boolean b) {
<caret>Assert.assertTrue("message", !b);
}
}
@@ -0,0 +1,9 @@
package com.siyeh.ipp.junit.flip_assert_literal;
import org.junit.Assert;
class Messsage {
void test(boolean b) {
Assert.assertFalse("message", b);
}
}
@@ -0,0 +1,36 @@
/**
* (c) 2013 Desert Island BV
* created: 08 09 2013
*/
package com.siyeh.ipp.junit;
import com.siyeh.IntentionPowerPackBundle;
import com.siyeh.ipp.IPPTestCase;
/**
* @see FlipAssertLiteralIntention
* @author Bas Leijdekkers
*/
public class FlipAssertLiteralIntentionTest extends IPPTestCase {
public void testMessage() { doTest(); }
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.addClass("package org.junit;" +
"class Assert {" +
" public static void assertTrue(java.lang.String message, boolean condition) {}" +
"}");
}
@Override
protected String getRelativePath() {
return "junit/flip_assert_literal";
}
@Override
protected String getIntentionName() {
return IntentionPowerPackBundle.message("flip.assert.literal.intention.name", "assertTrue", "assertFalse");
}
}