Fixed a bug in AssertThatBinaryExpression inspection for assertThat(null != expression) and related that would not correctly invert the condition on transformation.
This commit is contained in:
parent
2b97494c17
commit
acc81863f5
@ -567,6 +567,8 @@ Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for yo
|
||||
#### V1.6 (unreleased)
|
||||
- Really fixed AssertThatGuavaOptional inspections to avoid conversions from ```.get()``` to ```.contains()```
|
||||
for array types. Sigh. Shouldn't be working >12h a day and then do some more stuff at home.
|
||||
- Fixed a bug in AssertThatBinaryExpression inspection for ```assertThat(null != expression)``` and related
|
||||
that would not correctly invert the condition on transformation.
|
||||
|
||||
#### V1.5 (24-Sep-19)
|
||||
- Fix for AssertThatCollectionOrMap inspection sometimes causing an index out of bounds exception.
|
||||
|
@ -47,6 +47,8 @@ patchPluginXml {
|
||||
<ul>
|
||||
<li>Really fixed AssertThatGuavaOptional inspections to avoid conversions from .get() to .contains()
|
||||
for array types. Sigh. Shouldn't be working >12h a day and then do some more stuff at home.
|
||||
<li>Fixed a bug in AssertThatBinaryExpression inspection for assertThat(null != expression) and related
|
||||
that would not correctly invert the condition on transformation.
|
||||
</ul>
|
||||
<p>Full changelog available at <a href="https://github.com/chrisly42/cajon-plugin#changelog">Github project site</a>.</p>
|
||||
"""
|
||||
|
@ -38,7 +38,13 @@ class AssertThatBinaryExpressionInspection : AbstractAssertJInspection() {
|
||||
|
||||
if (isLeftNull && isRightNull) return
|
||||
if (isLeftNull || isRightNull) {
|
||||
val replacementMethod = expectedResult.map(MethodNames.IS_NULL, MethodNames.IS_NOT_NULL)
|
||||
val expectedResultOnOp =
|
||||
when (binaryExpression.operationTokenType) {
|
||||
JavaTokenType.EQEQ -> expectedResult
|
||||
JavaTokenType.NE -> !expectedResult
|
||||
else -> return
|
||||
}
|
||||
val replacementMethod = expectedResultOnOp.map(MethodNames.IS_NULL, MethodNames.IS_NOT_NULL)
|
||||
registerSplitMethod(holder, expectedCallExpression, replacementMethod) { desc, method ->
|
||||
SplitBinaryExpressionMethodCallQuickFix(desc, method, pickRightOperand = isLeftNull, noExpectedExpression = true)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ internal class AssertThatBinaryExpressionInspectionTest : AbstractCajonTest() {
|
||||
internal fun assertThat_of_binary_expression_can_be_moved_out(@MyFixture myFixture: JavaCodeInsightTestFixture) {
|
||||
myFixture.enableInspections(AssertThatBinaryExpressionInspection::class.java)
|
||||
myFixture.configureByFile("BinaryExpressionBefore.java")
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Split binary expression out of assertThat()"), 149)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Split binary expression out of assertThat()"), 161)
|
||||
myFixture.checkResultByFile("BinaryExpressionAfter.java")
|
||||
}
|
||||
}
|
@ -189,6 +189,20 @@ public class BinaryExpression {
|
||||
assertThat(stringAct).isNotNull();
|
||||
assertThat(stringAct).isNotNull();
|
||||
|
||||
assertThat(stringAct).as("doh!").isNotNull();
|
||||
assertThat(stringAct).isNotNull();
|
||||
assertThat(stringAct).isNotNull();
|
||||
assertThat(stringAct).isNull();
|
||||
assertThat(stringAct).isNull();
|
||||
assertThat(stringAct).isNull();
|
||||
|
||||
assertThat(stringAct).as("doh!").isNotNull();
|
||||
assertThat(stringAct).isNotNull();
|
||||
assertThat(stringAct).isNotNull();
|
||||
assertThat(stringAct).isNull();
|
||||
assertThat(stringAct).isNull();
|
||||
assertThat(stringAct).isNull();
|
||||
|
||||
assertThat(null == null).isTrue();
|
||||
assertThat(!false).isTrue();
|
||||
|
||||
|
@ -189,6 +189,20 @@ public class BinaryExpression {
|
||||
assertThat(null == stringAct).isEqualTo(false);
|
||||
assertThat(null == stringAct).isNotEqualTo(true);
|
||||
|
||||
assertThat(stringAct != null).as("doh!").isTrue();
|
||||
assertThat(stringAct != null).isEqualTo(true);
|
||||
assertThat(stringAct != null).isNotEqualTo(false);
|
||||
assertThat(stringAct != null).isFalse();
|
||||
assertThat(stringAct != null).isEqualTo(false);
|
||||
assertThat(stringAct != null).isNotEqualTo(true);
|
||||
|
||||
assertThat(null != stringAct).as("doh!").isTrue();
|
||||
assertThat(null != stringAct).isEqualTo(true);
|
||||
assertThat(null != stringAct).isNotEqualTo(false);
|
||||
assertThat(null != stringAct).isFalse();
|
||||
assertThat(null != stringAct).isEqualTo(false);
|
||||
assertThat(null != stringAct).isNotEqualTo(true);
|
||||
|
||||
assertThat(null == null).isTrue();
|
||||
assertThat(!false).isTrue();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user