diff --git a/README.md b/README.md index 09253b2..b2df9f3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/build.gradle b/build.gradle index e59ae61..9a0f55b 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,8 @@ patchPluginXml {

Full changelog available at Github project site.

""" diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspection.kt index 5bfab13..5f780b2 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspection.kt @@ -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) } diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt index b03f450..fd48e2f 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt @@ -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") } } \ No newline at end of file diff --git a/src/test/resources/inspections/BinaryExpression/BinaryExpressionAfter.java b/src/test/resources/inspections/BinaryExpression/BinaryExpressionAfter.java index 2f4fb36..2296360 100644 --- a/src/test/resources/inspections/BinaryExpression/BinaryExpressionAfter.java +++ b/src/test/resources/inspections/BinaryExpression/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(); diff --git a/src/test/resources/inspections/BinaryExpression/BinaryExpressionBefore.java b/src/test/resources/inspections/BinaryExpression/BinaryExpressionBefore.java index 76440f0..0bec92e 100644 --- a/src/test/resources/inspections/BinaryExpression/BinaryExpressionBefore.java +++ b/src/test/resources/inspections/BinaryExpression/BinaryExpressionBefore.java @@ -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();