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)
- - New AssertThatStringExpression intention 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 strings and CharSequences into account, too.
+
- Extended AssertThatSize inspection to take strings 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 (18-Apr-19)
diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspection.kt
similarity index 96%
rename from src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspection.kt
rename to src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspection.kt
index 90c6bf8..cf1e51d 100644
--- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspection.kt
+++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspection.kt
@@ -13,7 +13,7 @@ import de.platon42.intellij.plugins.cajon.map
import de.platon42.intellij.plugins.cajon.quickfixes.MoveActualOuterExpressionMethodCallQuickFix
import de.platon42.intellij.plugins.cajon.quickfixes.SplitBinaryExpressionMethodCallQuickFix
-class AssertThatBinaryExpressionIsTrueOrFalseInspection : AbstractAssertJInspection() {
+class AssertThatBinaryExpressionInspection : AbstractAssertJInspection() {
companion object {
private const val DISPLAY_NAME = "Asserting a binary expression"
@@ -63,13 +63,13 @@ class AssertThatBinaryExpressionIsTrueOrFalseInspection : AbstractAssertJInspect
val constantEvaluationHelper = JavaPsiFacade.getInstance(expression.project).constantEvaluationHelper
val swapExpectedAndActual = constantEvaluationHelper.computeConstantExpression(binaryExpression.lOperand) != null
- val tokenType = binaryExpression.operationSign.tokenType
+ val tokenType = binaryExpression.operationTokenType
.let {
if (swapExpectedAndActual) SWAP_SIDE_OF_BINARY_OPERATOR.getOrDefault(it, it) else it
}
.let {
if (expectedResult) it else INVERT_BINARY_OPERATOR.getOrDefault(it, it)
- } ?: return
+ }
val mappingToUse =
(isPrimitive || isNumericType).map(TOKEN_TO_ASSERTJ_FOR_PRIMITIVE_MAP, TOKEN_TO_ASSERTJ_FOR_OBJECT_MAPPINGS)
val replacementMethod = mappingToUse[tokenType] ?: return
diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanIsTrueOrFalseInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspection.kt
similarity index 92%
rename from src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanIsTrueOrFalseInspection.kt
rename to src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspection.kt
index 60a027e..6c02b21 100644
--- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanIsTrueOrFalseInspection.kt
+++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspection.kt
@@ -10,10 +10,10 @@ import de.platon42.intellij.plugins.cajon.MethodNames
import de.platon42.intellij.plugins.cajon.firstArg
import de.platon42.intellij.plugins.cajon.map
-class AssertThatBooleanIsTrueOrFalseInspection : AbstractAssertJInspection() {
+class AssertThatBooleanConditionInspection : AbstractAssertJInspection() {
companion object {
- private const val DISPLAY_NAME = "Asserting true or false"
+ private const val DISPLAY_NAME = "Asserting a boolean condition"
}
override fun getDisplayName() = DISPLAY_NAME
diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspection.kt
new file mode 100644
index 0000000..ead0dfa
--- /dev/null
+++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspection.kt
@@ -0,0 +1,50 @@
+package de.platon42.intellij.plugins.cajon.inspections
+
+import com.intellij.codeInspection.LocalQuickFix
+import com.intellij.codeInspection.ProblemsHolder
+import com.intellij.psi.*
+import de.platon42.intellij.plugins.cajon.MethodNames
+import de.platon42.intellij.plugins.cajon.findOutmostMethodCall
+import de.platon42.intellij.plugins.cajon.firstArg
+import de.platon42.intellij.plugins.cajon.quickfixes.RemoveUnaryExpressionQuickFix
+
+class AssertThatInvertedBooleanConditionInspection : AbstractAssertJInspection() {
+
+ companion object {
+ private const val DISPLAY_NAME = "Asserting an inverted boolean condition"
+ private const val INVERT_CONDITION_DESCRIPTION = "Invert condition in assertThat()"
+ private const val INVERT_CONDITION_MESSAGE = "Condition inside assertThat() could be inverted"
+ }
+
+ override fun getDisplayName() = DISPLAY_NAME
+
+ override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
+ return object : JavaElementVisitor() {
+ override fun visitMethodCallExpression(expression: PsiMethodCallExpression) {
+ super.visitMethodCallExpression(expression)
+ if (!ASSERT_THAT_BOOLEAN.test(expression)) {
+ return
+ }
+
+ val expectedCallExpression = expression.findOutmostMethodCall() ?: return
+ val expectedResult = getExpectedBooleanResult(expectedCallExpression) ?: return
+
+ val prefixExpression = expression.firstArg as? PsiPrefixExpression ?: return
+ if (prefixExpression.operationTokenType == JavaTokenType.EXCL) {
+ val replacementMethod = if (expectedResult) MethodNames.IS_FALSE else MethodNames.IS_TRUE
+ registerInvertMethod(holder, expression, replacementMethod, ::RemoveUnaryExpressionQuickFix)
+ }
+ }
+
+ private fun registerInvertMethod(
+ holder: ProblemsHolder,
+ expression: PsiMethodCallExpression,
+ replacementMethod: String,
+ quickFixSupplier: (String, String) -> LocalQuickFix
+ ) {
+ val quickfix = quickFixSupplier(INVERT_CONDITION_DESCRIPTION, replacementMethod)
+ holder.registerProblem(expression, INVERT_CONDITION_MESSAGE, quickfix)
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/quickfixes/RemoveUnaryExpressionQuickFix.kt b/src/main/java/de/platon42/intellij/plugins/cajon/quickfixes/RemoveUnaryExpressionQuickFix.kt
new file mode 100644
index 0000000..fc453ee
--- /dev/null
+++ b/src/main/java/de/platon42/intellij/plugins/cajon/quickfixes/RemoveUnaryExpressionQuickFix.kt
@@ -0,0 +1,30 @@
+package de.platon42.intellij.plugins.cajon.quickfixes
+
+import com.intellij.codeInspection.ProblemDescriptor
+import com.intellij.openapi.project.Project
+import com.intellij.psi.PsiMethodCallExpression
+import com.intellij.psi.PsiParenthesizedExpression
+import com.intellij.psi.PsiUnaryExpression
+import de.platon42.intellij.plugins.cajon.createExpectedMethodCall
+import de.platon42.intellij.plugins.cajon.findOutmostMethodCall
+import de.platon42.intellij.plugins.cajon.firstArg
+import de.platon42.intellij.plugins.cajon.replaceQualifierFromMethodCall
+
+class RemoveUnaryExpressionQuickFix(description: String, private val replacementMethod: String) : AbstractCommonQuickFix(description) {
+
+ override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
+ val element = descriptor.startElement
+ val methodCallExpression = element as? PsiMethodCallExpression ?: return
+ val assertExpression = methodCallExpression.firstArg as? PsiUnaryExpression ?: return
+ var operand = assertExpression.operand ?: return
+ while (operand is PsiParenthesizedExpression) {
+ operand = operand.expression ?: return
+ }
+ assertExpression.replace(operand)
+
+ val oldExpectedExpression = element.findOutmostMethodCall() ?: return
+ val expectedExpression = createExpectedMethodCall(element, replacementMethod)
+ expectedExpression.replaceQualifierFromMethodCall(oldExpectedExpression)
+ oldExpectedExpression.replace(expectedExpression)
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 2e1e802..94fb1a6 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -11,7 +11,7 @@
]]>
-
+
@@ -24,7 +24,7 @@
+ implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatBooleanConditionInspection"/>
+ implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatBinaryExpressionInspection"/>
+
diff --git a/src/main/resources/inspectionDescriptions/AssertThatBinaryExpressionIsTrueOrFalse.html b/src/main/resources/inspectionDescriptions/AssertThatBinaryExpression.html
similarity index 100%
rename from src/main/resources/inspectionDescriptions/AssertThatBinaryExpressionIsTrueOrFalse.html
rename to src/main/resources/inspectionDescriptions/AssertThatBinaryExpression.html
diff --git a/src/main/resources/inspectionDescriptions/AssertThatBooleanIsTrueOrFalse.html b/src/main/resources/inspectionDescriptions/AssertThatBooleanCondition.html
similarity index 100%
rename from src/main/resources/inspectionDescriptions/AssertThatBooleanIsTrueOrFalse.html
rename to src/main/resources/inspectionDescriptions/AssertThatBooleanCondition.html
diff --git a/src/main/resources/inspectionDescriptions/AssertThatInvertedBooleanCondition.html b/src/main/resources/inspectionDescriptions/AssertThatInvertedBooleanCondition.html
new file mode 100644
index 0000000..e949f13
--- /dev/null
+++ b/src/main/resources/inspectionDescriptions/AssertThatInvertedBooleanCondition.html
@@ -0,0 +1,7 @@
+
+
+Turns assertThat(!condition).isEqualTo(true/false) into assertThat(condition).isFalse()/isTrue().
+
+Also works with constant expressions and Boolean.TRUE/FALSE.
+
+
\ No newline at end of file
diff --git a/src/test/java/de/platon42/intellij/playground/Playground.java b/src/test/java/de/platon42/intellij/playground/Playground.java
index 3572ea8..ee4c728 100644
--- a/src/test/java/de/platon42/intellij/playground/Playground.java
+++ b/src/test/java/de/platon42/intellij/playground/Playground.java
@@ -243,6 +243,12 @@ public class Playground {
}
private void junitAssertions() {
+ assertFalse(!(new int[3].length == new ArrayList().size()));
+ assertThat(!(new int[3].length == new ArrayList().size())).isFalse();
+ assertThat((new int[3].length == new ArrayList().size())).isTrue();
+ assertThat(new int[3].length).isEqualTo(new ArrayList().size());
+ assertThat(new int[3]).hasSameSizeAs(new ArrayList());
+
assertTrue(true);
assertTrue("message", true);
assertFalse(true);
@@ -351,7 +357,6 @@ public class Playground {
assertThat(new Object()).extracting(Object::toString, Object::hashCode);
}
-
private void findReferences() {
Contact contact = new Contact();
List contactList = Collections.emptyList();
diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt
similarity index 87%
rename from src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspectionTest.kt
rename to src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt
index 9b30f19..0d317b4 100644
--- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionIsTrueOrFalseInspectionTest.kt
+++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt
@@ -6,13 +6,13 @@ import de.platon42.intellij.jupiter.TestDataSubPath
import de.platon42.intellij.plugins.cajon.AbstractCajonTest
import org.junit.jupiter.api.Test
-internal class AssertThatBinaryExpressionIsTrueOrFalseInspectionTest : AbstractCajonTest() {
+internal class AssertThatBinaryExpressionInspectionTest : AbstractCajonTest() {
@Test
@TestDataSubPath("inspections/BinaryExpression")
internal fun assertThat_of_binary_expression_can_be_moved_out(@MyFixture myFixture: JavaCodeInsightTestFixture) {
runTest {
- myFixture.enableInspections(AssertThatBinaryExpressionIsTrueOrFalseInspection::class.java)
+ myFixture.enableInspections(AssertThatBinaryExpressionInspection::class.java)
myFixture.configureByFile("BinaryExpressionBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Split binary expression out of assertThat()"), 148)
executeQuickFixes(myFixture, Regex.fromLiteral("Split equals() expression out of assertThat()"), 12)
diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanIsTrueOrFalseInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspectionTest.kt
similarity index 70%
rename from src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanIsTrueOrFalseInspectionTest.kt
rename to src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspectionTest.kt
index 5762e42..4934343 100644
--- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanIsTrueOrFalseInspectionTest.kt
+++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspectionTest.kt
@@ -6,19 +6,19 @@ import de.platon42.intellij.jupiter.TestDataSubPath
import de.platon42.intellij.plugins.cajon.AbstractCajonTest
import org.junit.jupiter.api.Test
-internal class AssertThatBooleanIsTrueOrFalseInspectionTest : AbstractCajonTest() {
+internal class AssertThatBooleanConditionInspectionTest : AbstractCajonTest() {
@Test
- @TestDataSubPath("inspections/BooleanIsTrueOrFalse")
+ @TestDataSubPath("inspections/BooleanCondition")
internal fun assertThat_with_isEqualTo_true_or_false_can_use_isTrue_or_isFalse(@MyFixture myFixture: JavaCodeInsightTestFixture) {
runTest {
- myFixture.enableInspections(AssertThatBooleanIsTrueOrFalseInspection::class.java)
- myFixture.configureByFile("BooleanIsTrueOrFalseBefore.java")
+ myFixture.enableInspections(AssertThatBooleanConditionInspection::class.java)
+ myFixture.configureByFile("BooleanConditionBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isTrue()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isFalse()"), 5)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isTrue()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isFalse()"), 4)
- myFixture.checkResultByFile("BooleanIsTrueOrFalseAfter.java")
+ myFixture.checkResultByFile("BooleanConditionAfter.java")
}
}
}
\ No newline at end of file
diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt
index 62d0c41..086c8ee 100644
--- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt
+++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt
@@ -9,14 +9,14 @@ import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
@AddLocalJarToModule(com.google.common.base.Optional::class, org.assertj.guava.api.Assertions::class, Assertions::class)
-@TestDataSubPath("inspections/AssertThatGuavaOptional")
+@TestDataSubPath("inspections/GuavaOptional")
internal class AssertThatGuavaOptionalInspectionTest : AbstractCajonTest() {
@Test
internal fun assertThat_get_or_isPresent_for_Guava_Optional_can_be_simplified(@MyFixture myFixture: JavaCodeInsightTestFixture) {
runTest {
myFixture.enableInspections(AssertThatGuavaOptionalInspection::class.java)
- myFixture.configureByFile("AssertThatGuavaOptionalBefore.java")
+ myFixture.configureByFile("GuavaOptionalBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isEqualTo() with isPresent()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isNotEqualTo() with isPresent()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isPresent()"), 3)
@@ -27,7 +27,7 @@ internal class AssertThatGuavaOptionalInspectionTest : AbstractCajonTest() {
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isFalse() with isAbsent()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isEqualTo() with contains()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove unwrapping of expected expression and replace isEqualTo() with contains()"), 6)
- myFixture.checkResultByFile("AssertThatGuavaOptionalAfter.java")
+ myFixture.checkResultByFile("GuavaOptionalAfter.java")
}
}
diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt
new file mode 100644
index 0000000..4c85f31
--- /dev/null
+++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt
@@ -0,0 +1,21 @@
+package de.platon42.intellij.plugins.cajon.inspections
+
+import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
+import de.platon42.intellij.jupiter.MyFixture
+import de.platon42.intellij.jupiter.TestDataSubPath
+import de.platon42.intellij.plugins.cajon.AbstractCajonTest
+import org.junit.jupiter.api.Test
+
+internal class AssertThatInvertedBooleanConditionInspectionTest : AbstractCajonTest() {
+
+ @Test
+ @TestDataSubPath("inspections/InvertedBooleanCondition")
+ internal fun assertThat_with_inverted_boolean_condition_can_be_inverted(@MyFixture myFixture: JavaCodeInsightTestFixture) {
+ runTest {
+ myFixture.enableInspections(AssertThatInvertedBooleanConditionInspection::class.java)
+ myFixture.configureByFile("InvertedBooleanConditionBefore.java")
+ executeQuickFixes(myFixture, Regex.fromLiteral("Invert condition in assertThat()"), 21)
+ myFixture.checkResultByFile("InvertedBooleanConditionAfter.java")
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt
index 5975a74..c2e1a85 100644
--- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt
+++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt
@@ -9,11 +9,11 @@ import org.junit.jupiter.api.Test
internal class AssertThatJava8OptionalInspectionTest : AbstractCajonTest() {
@Test
- @TestDataSubPath("inspections/AssertThatJava8Optional")
+ @TestDataSubPath("inspections/Java8Optional")
internal fun assertThat_get_or_isPresent_for_Java8_Optional_can_be_simplified(@MyFixture myFixture: JavaCodeInsightTestFixture) {
runTest {
myFixture.enableInspections(AssertThatJava8OptionalInspection::class.java)
- myFixture.configureByFile("AssertThatJava8OptionalBefore.java")
+ myFixture.configureByFile("Java8OptionalBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isEqualTo() with isPresent()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isNotEqualTo() with isPresent()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isEqualTo() with isNotPresent()"), 2)
@@ -25,7 +25,7 @@ internal class AssertThatJava8OptionalInspectionTest : AbstractCajonTest() {
executeQuickFixes(myFixture, Regex.fromLiteral("Remove unwrapping of expected expression and replace isEqualTo() with contains()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isEqualTo() with contains()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isSameAs() with containsSame()"), 1)
- myFixture.checkResultByFile("AssertThatJava8OptionalAfter.java")
+ myFixture.checkResultByFile("Java8OptionalAfter.java")
}
}
}
\ No newline at end of file
diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt
index e0b842a..e8f13d0 100644
--- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt
+++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt
@@ -9,11 +9,11 @@ import org.junit.jupiter.api.Test
internal class AssertThatSizeInspectionTest : AbstractCajonTest() {
@Test
- @TestDataSubPath("inspections/AssertThatSize")
+ @TestDataSubPath("inspections/Size")
internal fun assertThat_size_of_array_or_collection_can_be_simplified(@MyFixture myFixture: JavaCodeInsightTestFixture) {
runTest {
myFixture.enableInspections(AssertThatSizeInspection::class.java)
- myFixture.configureByFile("AssertThatSizeBefore.java")
+ myFixture.configureByFile("SizeBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isZero() with isEmpty()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotZero() with isNotEmpty()"), 4)
@@ -27,7 +27,7 @@ internal class AssertThatSizeInspectionTest : AbstractCajonTest() {
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThanOrEqualTo() with hasSizeGreaterThanOrEqualTo()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThan() with hasSizeLessThan()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThanOrEqualTo() with hasSizeLessThanOrEqualTo()"), 4)
- myFixture.checkResultByFile("AssertThatSizeAfter.java")
+ myFixture.checkResultByFile("SizeAfter.java")
}
}
}
\ No newline at end of file
diff --git a/src/test/resources/inspections/BooleanIsTrueOrFalse/BooleanIsTrueOrFalseAfter.java b/src/test/resources/inspections/BooleanCondition/BooleanConditionAfter.java
similarity index 92%
rename from src/test/resources/inspections/BooleanIsTrueOrFalse/BooleanIsTrueOrFalseAfter.java
rename to src/test/resources/inspections/BooleanCondition/BooleanConditionAfter.java
index afe2840..3610d63 100644
--- a/src/test/resources/inspections/BooleanIsTrueOrFalse/BooleanIsTrueOrFalseAfter.java
+++ b/src/test/resources/inspections/BooleanCondition/BooleanConditionAfter.java
@@ -1,8 +1,8 @@
import static org.assertj.core.api.Assertions.assertThat;
-public class BooleanIsTrueOrFalse {
+public class BooleanCondition {
- private void booleanIsTrueOrFalse() {
+ private void booleanCondition() {
boolean primitive = false;
Boolean object = Boolean.TRUE;
diff --git a/src/test/resources/inspections/BooleanIsTrueOrFalse/BooleanIsTrueOrFalseBefore.java b/src/test/resources/inspections/BooleanCondition/BooleanConditionBefore.java
similarity index 93%
rename from src/test/resources/inspections/BooleanIsTrueOrFalse/BooleanIsTrueOrFalseBefore.java
rename to src/test/resources/inspections/BooleanCondition/BooleanConditionBefore.java
index 6da7ac6..14ec27b 100644
--- a/src/test/resources/inspections/BooleanIsTrueOrFalse/BooleanIsTrueOrFalseBefore.java
+++ b/src/test/resources/inspections/BooleanCondition/BooleanConditionBefore.java
@@ -1,8 +1,8 @@
import static org.assertj.core.api.Assertions.assertThat;
-public class BooleanIsTrueOrFalse {
+public class BooleanCondition {
- private void booleanIsTrueOrFalse() {
+ private void booleanCondition() {
boolean primitive = false;
Boolean object = Boolean.TRUE;
diff --git a/src/test/resources/inspections/AssertThatGuavaOptional/AssertThatGuavaOptionalAfter.java b/src/test/resources/inspections/GuavaOptional/GuavaOptionalAfter.java
similarity index 95%
rename from src/test/resources/inspections/AssertThatGuavaOptional/AssertThatGuavaOptionalAfter.java
rename to src/test/resources/inspections/GuavaOptional/GuavaOptionalAfter.java
index dcedb28..d8fdec3 100644
--- a/src/test/resources/inspections/AssertThatGuavaOptional/AssertThatGuavaOptionalAfter.java
+++ b/src/test/resources/inspections/GuavaOptional/GuavaOptionalAfter.java
@@ -3,9 +3,9 @@ import com.google.common.base.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
-public class AssertThatGuavaOptional {
+public class GuavaOptional {
- private void assertThatGuavaOptional() {
+ private void guavaOptional() {
Optional opt = Optional.absent();
assertThat(opt).isPresent();
diff --git a/src/test/resources/inspections/AssertThatGuavaOptional/AssertThatGuavaOptionalBefore.java b/src/test/resources/inspections/GuavaOptional/GuavaOptionalBefore.java
similarity index 96%
rename from src/test/resources/inspections/AssertThatGuavaOptional/AssertThatGuavaOptionalBefore.java
rename to src/test/resources/inspections/GuavaOptional/GuavaOptionalBefore.java
index 8a8eb9d..640a3e1 100644
--- a/src/test/resources/inspections/AssertThatGuavaOptional/AssertThatGuavaOptionalBefore.java
+++ b/src/test/resources/inspections/GuavaOptional/GuavaOptionalBefore.java
@@ -3,9 +3,9 @@ import com.google.common.base.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
-public class AssertThatGuavaOptional {
+public class GuavaOptional {
- private void assertThatGuavaOptional() {
+ private void guavaOptional() {
Optional opt = Optional.absent();
assertThat(opt.isPresent()).isEqualTo(true);
diff --git a/src/test/resources/inspections/AssertThatGuavaOptional/WithoutPriorGuavaImportAfter.java b/src/test/resources/inspections/GuavaOptional/WithoutPriorGuavaImportAfter.java
similarity index 90%
rename from src/test/resources/inspections/AssertThatGuavaOptional/WithoutPriorGuavaImportAfter.java
rename to src/test/resources/inspections/GuavaOptional/WithoutPriorGuavaImportAfter.java
index e1236b8..8a4afaa 100644
--- a/src/test/resources/inspections/AssertThatGuavaOptional/WithoutPriorGuavaImportAfter.java
+++ b/src/test/resources/inspections/GuavaOptional/WithoutPriorGuavaImportAfter.java
@@ -3,9 +3,9 @@ import com.google.common.base.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
-public class AssertThatGuavaOptional {
+public class GuavaOptional {
- private void assertThatGuavaOptional() {
+ private void guavaOptional() {
Optional opt = Optional.absent();
assertThat(opt).contains("foo");
diff --git a/src/test/resources/inspections/AssertThatGuavaOptional/WithoutPriorGuavaImportBefore.java b/src/test/resources/inspections/GuavaOptional/WithoutPriorGuavaImportBefore.java
similarity index 90%
rename from src/test/resources/inspections/AssertThatGuavaOptional/WithoutPriorGuavaImportBefore.java
rename to src/test/resources/inspections/GuavaOptional/WithoutPriorGuavaImportBefore.java
index f6438bb..a89a7cd 100644
--- a/src/test/resources/inspections/AssertThatGuavaOptional/WithoutPriorGuavaImportBefore.java
+++ b/src/test/resources/inspections/GuavaOptional/WithoutPriorGuavaImportBefore.java
@@ -2,9 +2,9 @@ import com.google.common.base.Optional;
import static org.assertj.core.api.Assertions.assertThat;
-public class AssertThatGuavaOptional {
+public class GuavaOptional {
- private void assertThatGuavaOptional() {
+ private void guavaOptional() {
Optional opt = Optional.absent();
assertThat(opt).isEqualTo(Optional.of("foo"));
diff --git a/src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionAfter.java b/src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionAfter.java
new file mode 100644
index 0000000..4610f5d
--- /dev/null
+++ b/src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionAfter.java
@@ -0,0 +1,34 @@
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class InvertedBooleanCondition {
+
+ private void invertedBooleanCondition() {
+ boolean primitive = false;
+ Boolean object = Boolean.TRUE;
+
+ assertThat(primitive).isFalse();
+ assertThat(primitive).isFalse();
+ assertThat(primitive).isFalse();
+ assertThat(primitive).isFalse();
+ assertThat(primitive).isFalse();
+ assertThat(object).isFalse();
+ assertThat(object).isFalse();
+ assertThat(object).isFalse();
+ assertThat(object).isFalse();
+ assertThat(object).isFalse();
+
+ assertThat(primitive).isTrue();
+ assertThat(primitive).isTrue();
+ assertThat(primitive).isTrue();
+ assertThat(primitive).isTrue();
+ assertThat(primitive).isTrue();
+ assertThat(object).isTrue();
+ assertThat(object).isTrue();
+ assertThat(object).isTrue();
+ assertThat(object).isTrue();
+ assertThat(object).isTrue();
+
+ assertThat(!((primitive))).as("nah").isTrue();
+ assertThat(!object).isEqualTo(Boolean.TRUE && !Boolean.TRUE);
+ }
+}
diff --git a/src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionBefore.java b/src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionBefore.java
new file mode 100644
index 0000000..5dfe486
--- /dev/null
+++ b/src/test/resources/inspections/InvertedBooleanCondition/InvertedBooleanConditionBefore.java
@@ -0,0 +1,34 @@
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class InvertedBooleanCondition {
+
+ private void invertedBooleanCondition() {
+ boolean primitive = false;
+ Boolean object = Boolean.TRUE;
+
+ assertThat(!primitive).isEqualTo(Boolean.TRUE);
+ assertThat(!primitive).isEqualTo(true);
+ assertThat(!primitive).isNotEqualTo(Boolean.FALSE);
+ assertThat(!primitive).isNotEqualTo(false);
+ assertThat(!primitive).isTrue();
+ assertThat(!object).isEqualTo(Boolean.TRUE);
+ assertThat(!object).isEqualTo(true);
+ assertThat(!object).isNotEqualTo(Boolean.FALSE);
+ assertThat(!object).isNotEqualTo(false);
+ assertThat(!object).isTrue();
+
+ assertThat(!primitive).isEqualTo(Boolean.FALSE);
+ assertThat(!primitive).isEqualTo(false);
+ assertThat(!primitive).isNotEqualTo(Boolean.TRUE);
+ assertThat(!primitive).isNotEqualTo(true);
+ assertThat(!primitive).isFalse();
+ assertThat(!object).isEqualTo(Boolean.FALSE);
+ assertThat(!object).isEqualTo(false);
+ assertThat(!object).isNotEqualTo(Boolean.TRUE);
+ assertThat(!object).isNotEqualTo(true);
+ assertThat(!object).isFalse();
+
+ assertThat(!(((!((primitive)))))).as("nah").isEqualTo(true && !true);
+ assertThat(!object).isEqualTo(Boolean.TRUE && !Boolean.TRUE);
+ }
+}
diff --git a/src/test/resources/inspections/AssertThatJava8Optional/AssertThatJava8OptionalAfter.java b/src/test/resources/inspections/Java8Optional/Java8OptionalAfter.java
similarity index 92%
rename from src/test/resources/inspections/AssertThatJava8Optional/AssertThatJava8OptionalAfter.java
rename to src/test/resources/inspections/Java8Optional/Java8OptionalAfter.java
index 5a6e0ae..fd259ac 100644
--- a/src/test/resources/inspections/AssertThatJava8Optional/AssertThatJava8OptionalAfter.java
+++ b/src/test/resources/inspections/Java8Optional/Java8OptionalAfter.java
@@ -2,9 +2,9 @@ import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
-public class AssertThatJava8Optional {
+public class Java8Optional {
- private void assertThatJava8Optional() {
+ private void java8Optional() {
Optional opt = Optional.empty();
assertThat(opt).isPresent();
diff --git a/src/test/resources/inspections/AssertThatJava8Optional/AssertThatJava8OptionalBefore.java b/src/test/resources/inspections/Java8Optional/Java8OptionalBefore.java
similarity index 93%
rename from src/test/resources/inspections/AssertThatJava8Optional/AssertThatJava8OptionalBefore.java
rename to src/test/resources/inspections/Java8Optional/Java8OptionalBefore.java
index 70fefbe..ae1ed90 100644
--- a/src/test/resources/inspections/AssertThatJava8Optional/AssertThatJava8OptionalBefore.java
+++ b/src/test/resources/inspections/Java8Optional/Java8OptionalBefore.java
@@ -2,9 +2,9 @@ import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
-public class AssertThatJava8Optional {
+public class Java8Optional {
- private void assertThatJava8Optional() {
+ private void java8Optional() {
Optional opt = Optional.empty();
assertThat(opt.isPresent()).isEqualTo(true);
diff --git a/src/test/resources/inspections/AssertThatSize/AssertThatSizeAfter.java b/src/test/resources/inspections/Size/SizeAfter.java
similarity index 98%
rename from src/test/resources/inspections/AssertThatSize/AssertThatSizeAfter.java
rename to src/test/resources/inspections/Size/SizeAfter.java
index 8c496bd..18c5077 100644
--- a/src/test/resources/inspections/AssertThatSize/AssertThatSizeAfter.java
+++ b/src/test/resources/inspections/Size/SizeAfter.java
@@ -2,9 +2,9 @@ import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
-public class AssertThatSize {
+public class Size {
- private void assertThatSize() {
+ private void size() {
ArrayList list = new ArrayList<>();
ArrayList otherList = new ArrayList<>();
long[] array = new long[5];
diff --git a/src/test/resources/inspections/AssertThatSize/AssertThatSizeBefore.java b/src/test/resources/inspections/Size/SizeBefore.java
similarity index 98%
rename from src/test/resources/inspections/AssertThatSize/AssertThatSizeBefore.java
rename to src/test/resources/inspections/Size/SizeBefore.java
index c9f00b4..bc7ea07 100644
--- a/src/test/resources/inspections/AssertThatSize/AssertThatSizeBefore.java
+++ b/src/test/resources/inspections/Size/SizeBefore.java
@@ -2,9 +2,9 @@ import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
-public class AssertThatSize {
+public class Size {
- private void assertThatSize() {
+ private void size() {
ArrayList list = new ArrayList<>();
ArrayList otherList = new ArrayList<>();
long[] array = new long[5];