From db02f7fb937df17bb7fff94ab2a0bab6050da3dd Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Sat, 20 Apr 2019 18:40:38 +0200 Subject: [PATCH] New AssertThatInvertedBooleanCondition inspection that will remove inverted boolean expressions inside assertThat(). Renamed a few inspections to better/shorter names (and fixed file and directory names accordingly). --- README.md | 26 +++++++--- build.gradle | 6 ++- ...> AssertThatBinaryExpressionInspection.kt} | 6 +-- ...> AssertThatBooleanConditionInspection.kt} | 4 +- ...tThatInvertedBooleanConditionInspection.kt | 50 +++++++++++++++++++ .../RemoveUnaryExpressionQuickFix.kt | 30 +++++++++++ src/main/resources/META-INF/plugin.xml | 8 +-- ...e.html => AssertThatBinaryExpression.html} | 0 ...e.html => AssertThatBooleanCondition.html} | 0 .../AssertThatInvertedBooleanCondition.html | 7 +++ .../intellij/playground/Playground.java | 7 ++- ...sertThatBinaryExpressionInspectionTest.kt} | 4 +- ...sertThatBooleanConditionInspectionTest.kt} | 10 ++-- .../AssertThatGuavaOptionalInspectionTest.kt | 6 +-- ...tInvertedBooleanConditionInspectionTest.kt | 21 ++++++++ .../AssertThatJava8OptionalInspectionTest.kt | 6 +-- .../AssertThatSizeInspectionTest.kt | 6 +-- .../BooleanConditionAfter.java} | 4 +- .../BooleanConditionBefore.java} | 4 +- .../GuavaOptionalAfter.java} | 4 +- .../GuavaOptionalBefore.java} | 4 +- .../WithoutPriorGuavaImportAfter.java | 4 +- .../WithoutPriorGuavaImportBefore.java | 4 +- .../InvertedBooleanConditionAfter.java | 34 +++++++++++++ .../InvertedBooleanConditionBefore.java | 34 +++++++++++++ .../Java8OptionalAfter.java} | 4 +- .../Java8OptionalBefore.java} | 4 +- .../SizeAfter.java} | 4 +- .../SizeBefore.java} | 4 +- 29 files changed, 250 insertions(+), 55 deletions(-) rename src/main/java/de/platon42/intellij/plugins/cajon/inspections/{AssertThatBinaryExpressionIsTrueOrFalseInspection.kt => AssertThatBinaryExpressionInspection.kt} (96%) rename src/main/java/de/platon42/intellij/plugins/cajon/inspections/{AssertThatBooleanIsTrueOrFalseInspection.kt => AssertThatBooleanConditionInspection.kt} (92%) create mode 100644 src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspection.kt create mode 100644 src/main/java/de/platon42/intellij/plugins/cajon/quickfixes/RemoveUnaryExpressionQuickFix.kt rename src/main/resources/inspectionDescriptions/{AssertThatBinaryExpressionIsTrueOrFalse.html => AssertThatBinaryExpression.html} (100%) rename src/main/resources/inspectionDescriptions/{AssertThatBooleanIsTrueOrFalse.html => AssertThatBooleanCondition.html} (100%) create mode 100644 src/main/resources/inspectionDescriptions/AssertThatInvertedBooleanCondition.html rename src/test/java/de/platon42/intellij/plugins/cajon/inspections/{AssertThatBinaryExpressionIsTrueOrFalseInspectionTest.kt => AssertThatBinaryExpressionInspectionTest.kt} (87%) rename src/test/java/de/platon42/intellij/plugins/cajon/inspections/{AssertThatBooleanIsTrueOrFalseInspectionTest.kt => AssertThatBooleanConditionInspectionTest.kt} (70%) create mode 100644 src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt rename src/test/resources/inspections/{BooleanIsTrueOrFalse/BooleanIsTrueOrFalseAfter.java => BooleanCondition/BooleanConditionAfter.java} (92%) rename src/test/resources/inspections/{BooleanIsTrueOrFalse/BooleanIsTrueOrFalseBefore.java => BooleanCondition/BooleanConditionBefore.java} (93%) rename src/test/resources/inspections/{AssertThatGuavaOptional/AssertThatGuavaOptionalAfter.java => GuavaOptional/GuavaOptionalAfter.java} (95%) rename src/test/resources/inspections/{AssertThatGuavaOptional/AssertThatGuavaOptionalBefore.java => GuavaOptional/GuavaOptionalBefore.java} (96%) rename src/test/resources/inspections/{AssertThatGuavaOptional => GuavaOptional}/WithoutPriorGuavaImportAfter.java (90%) rename src/test/resources/inspections/{AssertThatGuavaOptional => GuavaOptional}/WithoutPriorGuavaImportBefore.java (90%) create mode 100644 src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionAfter.java create mode 100644 src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionBefore.java rename src/test/resources/inspections/{AssertThatJava8Optional/AssertThatJava8OptionalAfter.java => Java8Optional/Java8OptionalAfter.java} (92%) rename src/test/resources/inspections/{AssertThatJava8Optional/AssertThatJava8OptionalBefore.java => Java8Optional/Java8OptionalBefore.java} (93%) rename src/test/resources/inspections/{AssertThatSize/AssertThatSizeAfter.java => Size/SizeAfter.java} (98%) rename src/test/resources/inspections/{AssertThatSize/AssertThatSizeBefore.java => Size/SizeBefore.java} (98%) diff --git a/README.md b/README.md index 49afc2b..02ed35c 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,13 @@ Applying a quick fix might result in further optimization possibilities, so you For example: ``` -assertFalse(!(array.length() == collection.size())); +assertFalse(!(array.length == collection.size())); -assertThat(!(array.length() == collection.size())).isFalse(); +assertThat(!(array.length == collection.size())).isFalse(); -assertThat(array.length() == collection.size()).isTrue(); +assertThat(array.length == collection.size()).isTrue(); + +assertThat(array.length).isEqualTo(collection.size()); assertThat(array).hasSameSizeAs(collection); ``` @@ -76,12 +78,19 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the to: assertThat(object).isNotNull(); ``` -- AssertThatBooleanIsTrueOrFalse +- AssertThatBooleanCondition ``` from: assertThat(booleanValue).isEqualTo(true/false/Boolean.TRUE/Boolean.FALSE); to: assertThat(booleanValue).isTrue()/isFalse(); ``` +- AssertThatInvertedBooleanCondition + ``` + from: assertThat(!booleanValue).isEqualTo(true/false/Boolean.TRUE/Boolean.FALSE); + from: assertThat(!booleanValue).isTrue()/isFalse(); + to: assertThat(!booleanValue).isFalse()/isTrue(); + ``` + - AssertThatStringIsEmpty ``` from: assertThat(charSequence/string).isEqualTo(""); @@ -160,7 +169,7 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the to: assertThat("string").hasSameSizeAs(collection); ``` -- AssertThatBinaryExpressionIsTrueOrFalse +- AssertThatBinaryExpression ``` from: assertThat(primActual == primExpected).isTrue(); to: assertThat(primActual).isEqualTo(primExpected); @@ -292,7 +301,6 @@ The IntelliJ framework actually uses the JUnit 3 TestCase for plugin testing and Feel free to use the code (in package de.platon42.intellij.jupiter) for your projects (with attribution). ## TODO -- AssertThatNegatedBooleanExpression - AssertThatInstanceOf - AssumeThatInsteadOfReturn - Join consecutive assertThats @@ -307,9 +315,11 @@ Feel free to use the code (in package de.platon42.intellij.jupiter) for your pro ## Changelog #### V0.6 (unreleased) -- New AssertThatStringExpression that will move ```isEmpty()```, ```equals()```, ```equalsIgnoreCase()```, ```contains()```, +- New AssertThatStringExpression inspection that will move ```isEmpty()```, ```equals()```, ```equalsIgnoreCase()```, ```contains()```, ```startsWith()```, and ```endsWith()``` out of actual expression. -- Extended AssertThatSize intention to take ```String```s and ```CharSequences``` into account, too. +- Extended AssertThatSize inspection to take ```String```s and ```CharSequences``` into account, too. +- New AssertThatInvertedBooleanCondition inspection that will remove inverted boolean expressions inside ```assertThat()```. +- Renamed a few inspections to better/shorter names. #### V0.5 (13-Apr-19) - Fixed incompatibility with IDEA versions < 2018.2 (affected AssertThatSizeInspection). Minimal version is now 2017.3. diff --git a/build.gradle b/build.gradle index 2f5cee7..10f2b69 100644 --- a/build.gradle +++ b/build.gradle @@ -42,9 +42,11 @@ patchPluginXml { changeNotes """

V0.6 (xx-Apr-19)

V0.5 (18-Apr-19)