From 178b7d368a37a0bcd2ac851b6c4f84b4f7ecb094 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Fri, 17 May 2019 12:17:01 +0200 Subject: [PATCH] Extended JUnitAssertToAssertJ inspection to convert JUnit assume-Statements, too. Improved JUnitAssertToAssertJ quick fix to swap expected and actual expressions if the actual one is a constant. --- README.md | 24 ++++-- build.gradle | 2 + .../intellij/plugins/cajon/Extensions.kt | 9 +- .../platon42/intellij/plugins/cajon/Helper.kt | 4 + .../AbstractJUnitAssertInspection.kt | 12 +++ .../JUnitAssertToAssertJInspection.kt | 83 ++++++++++++++----- .../ReplaceJUnitAssertMethodCallQuickFix.kt | 13 ++- .../ReplaceJUnitAssumeMethodCallQuickFix.kt | 41 +++++++++ ...placeJUnitDeltaAssertMethodCallQuickFix.kt | 12 ++- .../JUnitAssertToAssertJInspectionTest.kt | 3 +- .../JUnitAssertToAssertJInspectionAfter.java | 36 ++++++++ .../JUnitAssertToAssertJInspectionBefore.java | 35 ++++++++ 12 files changed, 239 insertions(+), 35 deletions(-) create mode 100644 src/main/java/de/platon42/intellij/plugins/cajon/quickfixes/ReplaceJUnitAssumeMethodCallQuickFix.kt diff --git a/README.md b/README.md index 477abf0..0b1e14b 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,8 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the except for method calls with known side-effect methods such as ```Iterator.next()``` and pre/post-increment/decrement operations -- please notify me about others. - The comments of the statements will be preserved. When using ```.extracting()``` or similar, the statements will not be merged. + The comments of the statements will be preserved. When using ```extracting()``` or similar, + the statements will not be merged. - AssertThatObjectIsNullOrNotNull @@ -366,7 +367,7 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the as being skipped. Return statements in ```if``` statements in main test methods (must be annotated with JUnit 4 or - Jupiter @Test annotations) will be verified to have at least one ```assertThat()``` statement in the code flow. + Jupiter ```@Test``` annotations) will be verified to have at least one ```assertThat()``` statement in the code flow. Method calls within the same class will be examined for ```assertThat()``` statements, too. However, at most 50 statements and down to five recursions will be tolerated before giving up. @@ -402,7 +403,10 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the - JUnitAssertToAssertJ - Tries to convert most of the JUnit 4 assertions to AssertJ format. + Tries to convert most of the JUnit 4 assertions and assumptions to AssertJ format. + Sometimes the expected and actual expressions are specified in wrong order -- + Cajon tries to swap these when it detects the supposed actual expression to be a + constant while the expected one is not. Does not support Hamcrest-Matchers. If you need that kind of conversion, you might want to check out the @@ -415,8 +419,8 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the assertFalse(message, condition); assertNull(object); assertNull(message, object); - assertNonNull(object); - assertNonNull(message, object); + assertNotNull(object); + assertNotNull(message, object); assertEquals(expected, actual); assertEquals(message, expected, actual); assertEquals(expectedDoubleOrFloat, actualDoubleOrFloat, delta); @@ -433,6 +437,14 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the assertArrayEquals(message, expectedArray, actualArray); assertArrayEquals(expectedDoubleOrFloatArray, actualDoubleOrFloatArray, delta); assertArrayEquals(message, expectedDoubleOrFloatArray, actualDoubleOrFloatArray, delta); + + assumeTrue(condition); + assumeTrue(message, condition); + assumeFalse(condition); + assumeFalse(message, condition); + assumeNotNull(object); // single argument only! + assumeNoException(throwable); + assumeNoException(message, throwable); ``` ### Implemented referencing @@ -478,6 +490,8 @@ Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for yo - Improved JoinAssertThatStatements detection of expressions with side-effects and added pre/post-increment/decrement detection. - Added Guava Optional ```opt.orNull() == null``` case. You know, I'm not making this stuff up, people actually write this kind of code. - Added Java 8 Optional ```opt.orElse(null) == null``` case, too. +- Extended JUnitAssertToAssertJ inspection to convert JUnit ```assume```-Statements, too. +- Improved JUnitAssertToAssertJ quick fix to swap expected and actual expressions if the actual one is a constant. #### V1.0 (06-May-19) - First release to be considered stable enough for production use. diff --git a/build.gradle b/build.gradle index d7631cb..8b64cd8 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,8 @@ patchPluginXml {
  • Improved JoinAssertThatStatements detection of expressions with side-effects and added pre/post-increment/decrement detection.
  • Added Guava Optional opt.orNull() == null case. You know, I'm not making this stuff up, people actually write this kind of code.
  • Added Java 8 Optional opt.orElse(null) == null case, too. +
  • Extended JUnitAssertToAssertJ inspection to convert JUnit assume-Statements, too. +
  • Improved JUnitAssertToAssertJ quick fix to swap expected and actual expressions if the actual one is a constant.

    V1.0 (06-May-19)