From 5812e7222742de25a590962438c5887350691a24 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Sun, 7 Apr 2019 11:29:07 +0200 Subject: [PATCH] New inspection AssertThatBinaryExpressionIsTrueOrFalse that will find and fix common binary expressions and equals() statements (more than 150 combinations) inside assertThat(). --- README.md | 17 ++ build.gradle | 3 +- .../inspections/AbstractAssertJInspection.kt | 14 ++ ...BinaryExpressionIsTrueOrFalseInspection.kt | 144 +++++++++++++ ...SplitBinaryExpressionMethodCallQuickFix.kt | 36 ++++ ...SplitEqualsExpressionMethodCallQuickFix.kt | 28 +++ src/main/resources/META-INF/plugin.xml | 15 +- ...sertThatBinaryExpressionIsTrueOrFalse.html | 11 + .../intellij/playground/Playground.java | 57 +++++- ...ryExpressionIsTrueOrFalseInspectionTest.kt | 22 ++ .../BinaryExpressionAfter.java | 190 ++++++++++++++++++ .../BinaryExpressionBefore.java | 190 ++++++++++++++++++ 12 files changed, 712 insertions(+), 15 deletions(-) create mode 100644 src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspection.kt create mode 100644 src/main/java/de/platon42/intellij/plugins/cajon/quickfixes/SplitBinaryExpressionMethodCallQuickFix.kt create mode 100644 src/main/java/de/platon42/intellij/plugins/cajon/quickfixes/SplitEqualsExpressionMethodCallQuickFix.kt create mode 100644 src/main/resources/inspectionDescriptions/AssertThatBinaryExpressionIsTrueOrFalse.html create mode 100644 src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspectionTest.kt create mode 100644 src/test/resources/inspections/BinaryExpression/BinaryExpressionAfter.java create mode 100644 src/test/resources/inspections/BinaryExpression/BinaryExpressionBefore.java diff --git a/README.md b/README.md index 716bc32..060194f 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,22 @@ The plugin also supports the conversion of the most common JUnit 4 assertions to and analogously for collections... +- AssertThatBinaryExpressionIsTrueOrFalse + ``` + from: assertThat(primActual == primExpected).isTrue(); + to: assertThat(primActual).isEqualTo(primExpected); + + from: assertThat(10 < primActual).isNotEqualTo(false); + to: assertThat(primActual).isGreaterThan(primExpected); + + from: assertThat(objActual != objExpected).isEqualTo(true); + to: assertThat(objActual).isNotSameAs(objExpected); + + from: assertThat(null == objActual).isFalse(); + to: assertThat(objActual).isNotNull(); + ``` + and many, many more combinations (more than 150). + - JUnitAssertToAssertJ ``` assertTrue(condition); @@ -182,3 +198,4 @@ Feel free to use the code (in package de.platon42.intellij.jupiter) for your pro from: assertThat(object).extracting("propOne", "propNoGetter", "propTwo.innerProp")... to: assertThat(object).extracting(type::getPropOne, it -> it.propNoGetter, it -> it.getPropTwo().getInnerProp())... ``` +- Kotlin support diff --git a/build.gradle b/build.gradle index c5200b6..ef2c297 100644 --- a/build.gradle +++ b/build.gradle @@ -41,8 +41,9 @@ intellij { patchPluginXml { changeNotes """ -

V0.3 (xx-Apr-19)

+

V0.3 (07-Apr-19)