Fixed a NPE in AssumeThatInsteadOfReturn inspection quickfix for empty else branches.
Fixed missing description for AssumeThatInsteadOfReturn inspection. Added new AssertThatCollectionOrMapExpression inspection that tries to pull out methods such as isEmpty() or contains() out of an actual assertThat() expression. Added more method calls that are considered extension points.
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
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 AssertThatCollectionOrMapExpressionInspectionTest : AbstractCajonTest() {
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("inspections/CollectionMapExpression")
|
||||
internal fun assertThat_with_certain_Collection_and_Map_methods(@MyFixture myFixture: JavaCodeInsightTestFixture) {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatCollectionOrMapExpressionInspection::class.java)
|
||||
myFixture.configureByFile("CollectionMapExpressionBefore.java")
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isEmpty() instead"), 4)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().contains() instead"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsAll() of actual expression and use assertThat().containsAll() instead"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsKey() of actual expression and use assertThat().containsKey() instead"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsValue() of actual expression and use assertThat().containsValue() instead"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isNotEmpty() instead"), 5)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().doesNotContain() instead"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsKey() of actual expression and use assertThat().doesNotContainKey() instead"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsValue() of actual expression and use assertThat().doesNotContainValue() instead"), 2)
|
||||
myFixture.checkResultByFile("CollectionMapExpressionAfter.java")
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@ internal class AssumeThatInsteadOfReturnInspectionTest : AbstractCajonTest() {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssumeThatInsteadOfReturnInspection::class.java)
|
||||
myFixture.configureByFile("AssumeThatBefore.java")
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace if statement by assumeTrue()"), 4)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace if statement by assumeTrue()"), 5)
|
||||
myFixture.checkResultByFile("AssumeThatAfter.java")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,13 @@ public class AssumeThat {
|
||||
assertThat(foobar).isNotEmpty();
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void junit5_return_with_empty_else_block() {
|
||||
String foobar = System.getProperty("car_manufacturer");
|
||||
assumeThat(foobar.equals("Volkswagen")).isFalse();
|
||||
assertThat(foobar).isNotEmpty();
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.TestTemplate
|
||||
public void junit5_return_inside_recursion_with_comments() {
|
||||
String foobar = System.getProperty("car_manufacturer");
|
||||
|
||||
@@ -39,6 +39,13 @@ public class AssumeThat {
|
||||
assertThat(foobar).isNotEmpty();
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void junit5_return_with_empty_else_block() {
|
||||
String foobar = System.getProperty("car_manufacturer");
|
||||
if (foobar.equals("Volkswagen")) return; else {}
|
||||
assertThat(foobar).isNotEmpty();
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.TestTemplate
|
||||
public void junit5_return_inside_recursion_with_comments() {
|
||||
String foobar = System.getProperty("car_manufacturer");
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CollectionMapExpression {
|
||||
|
||||
private void collectionMapExpression() {
|
||||
List<String> stringList = new ArrayList<>();
|
||||
List<String> anotherList = new ArrayList<>();
|
||||
Map<String, Integer> keyValueMap = new HashMap<>();
|
||||
|
||||
assertThat(stringList).as("foo").isEmpty();
|
||||
assertThat(stringList).isEmpty();
|
||||
assertThat(stringList).contains("foo");
|
||||
assertThat(stringList).contains("foo");
|
||||
assertThat(stringList).containsAll(anotherList);
|
||||
assertThat(stringList).containsAll(anotherList);
|
||||
|
||||
assertThat(stringList).as("foo").isNotEmpty();
|
||||
assertThat(stringList).isNotEmpty();
|
||||
assertThat(stringList).doesNotContain("foo");
|
||||
assertThat(stringList).doesNotContain("foo");
|
||||
assertThat(stringList.containsAll(anotherList)).isEqualTo(false);
|
||||
assertThat(stringList.containsAll(anotherList)).isFalse();
|
||||
|
||||
assertThat(keyValueMap).as("foo").isEmpty();
|
||||
assertThat(keyValueMap).isEmpty();
|
||||
assertThat(keyValueMap).containsKey("foo");
|
||||
assertThat(keyValueMap).containsKey("foo");
|
||||
assertThat(keyValueMap).containsValue(2);
|
||||
assertThat(keyValueMap).containsValue(2);
|
||||
|
||||
assertThat(keyValueMap).as("foo").isNotEmpty();
|
||||
assertThat(keyValueMap).isNotEmpty();
|
||||
assertThat(keyValueMap).doesNotContainKey("foo");
|
||||
assertThat(keyValueMap).doesNotContainKey("foo");
|
||||
assertThat(keyValueMap).doesNotContainValue(2);
|
||||
assertThat(keyValueMap).doesNotContainValue(2);
|
||||
|
||||
assertThat(stringList).as("foo").isNotEmpty().as("bar").isNotEmpty();
|
||||
assertThat(stringList.isEmpty()).as("foo").isEqualTo(false).as("bar").isTrue();
|
||||
assertThat(stringList.isEmpty()).as("foo").satisfies(it -> it.booleanValue()).as("bar").isFalse();
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CollectionMapExpression {
|
||||
|
||||
private void collectionMapExpression() {
|
||||
List<String> stringList = new ArrayList<>();
|
||||
List<String> anotherList = new ArrayList<>();
|
||||
Map<String, Integer> keyValueMap = new HashMap<>();
|
||||
|
||||
assertThat(stringList.isEmpty()).as("foo").isEqualTo(true);
|
||||
assertThat(stringList.isEmpty()).isTrue();
|
||||
assertThat(stringList.contains("foo")).isEqualTo(true);
|
||||
assertThat(stringList.contains("foo")).isTrue();
|
||||
assertThat(stringList.containsAll(anotherList)).isEqualTo(true);
|
||||
assertThat(stringList.containsAll(anotherList)).isTrue();
|
||||
|
||||
assertThat(stringList.isEmpty()).as("foo").isEqualTo(false);
|
||||
assertThat(stringList.isEmpty()).isFalse();
|
||||
assertThat(stringList.contains("foo")).isEqualTo(false);
|
||||
assertThat(stringList.contains("foo")).isFalse();
|
||||
assertThat(stringList.containsAll(anotherList)).isEqualTo(false);
|
||||
assertThat(stringList.containsAll(anotherList)).isFalse();
|
||||
|
||||
assertThat(keyValueMap.isEmpty()).as("foo").isEqualTo(true);
|
||||
assertThat(keyValueMap.isEmpty()).isTrue();
|
||||
assertThat(keyValueMap.containsKey("foo")).isEqualTo(true);
|
||||
assertThat(keyValueMap.containsKey("foo")).isTrue();
|
||||
assertThat(keyValueMap.containsValue(2)).isEqualTo(true);
|
||||
assertThat(keyValueMap.containsValue(2)).isTrue();
|
||||
|
||||
assertThat(keyValueMap.isEmpty()).as("foo").isEqualTo(false);
|
||||
assertThat(keyValueMap.isEmpty()).isFalse();
|
||||
assertThat(keyValueMap.containsKey("foo")).isEqualTo(false);
|
||||
assertThat(keyValueMap.containsKey("foo")).isFalse();
|
||||
assertThat(keyValueMap.containsValue(2)).isEqualTo(false);
|
||||
assertThat(keyValueMap.containsValue(2)).isFalse();
|
||||
|
||||
assertThat(stringList.isEmpty()).as("foo").isEqualTo(false).as("bar").isFalse();
|
||||
assertThat(stringList.isEmpty()).as("foo").isEqualTo(false).as("bar").isTrue();
|
||||
assertThat(stringList.isEmpty()).as("foo").satisfies(it -> it.booleanValue()).as("bar").isFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user