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:
@@ -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