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).
This commit is contained in:
@@ -243,6 +243,12 @@ public class Playground {
|
||||
}
|
||||
|
||||
private void junitAssertions() {
|
||||
assertFalse(!(new int[3].length == new ArrayList<Integer>().size()));
|
||||
assertThat(!(new int[3].length == new ArrayList<Integer>().size())).isFalse();
|
||||
assertThat((new int[3].length == new ArrayList<Integer>().size())).isTrue();
|
||||
assertThat(new int[3].length).isEqualTo(new ArrayList<Integer>().size());
|
||||
assertThat(new int[3]).hasSameSizeAs(new ArrayList<Integer>());
|
||||
|
||||
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<Contact> contactList = Collections.emptyList();
|
||||
|
||||
+2
-2
@@ -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)
|
||||
+5
-5
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+2
-2
@@ -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<String> opt = Optional.absent();
|
||||
|
||||
assertThat(opt).isPresent();
|
||||
+2
-2
@@ -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<String> opt = Optional.absent();
|
||||
|
||||
assertThat(opt.isPresent()).isEqualTo(true);
|
||||
+2
-2
@@ -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<String> opt = Optional.absent();
|
||||
|
||||
assertThat(opt).contains("foo");
|
||||
+2
-2
@@ -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<String> opt = Optional.absent();
|
||||
|
||||
assertThat(opt).isEqualTo(Optional.of("foo"));
|
||||
+34
@@ -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);
|
||||
}
|
||||
}
|
||||
+34
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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<String> opt = Optional.empty();
|
||||
|
||||
assertThat(opt).isPresent();
|
||||
+2
-2
@@ -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<String> opt = Optional.empty();
|
||||
|
||||
assertThat(opt.isPresent()).isEqualTo(true);
|
||||
+2
-2
@@ -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<String> list = new ArrayList<>();
|
||||
ArrayList<String> otherList = new ArrayList<>();
|
||||
long[] array = new long[5];
|
||||
+2
-2
@@ -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<String> list = new ArrayList<>();
|
||||
ArrayList<String> otherList = new ArrayList<>();
|
||||
long[] array = new long[5];
|
||||
Reference in New Issue
Block a user