Implemented AssertThatEnumerableIsEmptyInspection. Improved literal values by constant value calculation, more refactoring.
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
package de.platon42.intellij.playground;
|
||||
|
||||
import org.assertj.core.api.ListAssert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class Playground {
|
||||
|
||||
private void sizeOfList() {
|
||||
assertThat("string").as("foo").hasSize(0);
|
||||
assertThat(new StringBuilder()).as("bar").hasSize(0);
|
||||
ListAssert<String> etc = assertThat(new ArrayList<String>()).as("etc");
|
||||
etc.hasSize(0);
|
||||
assertThat(new Long[1]).as("etc").hasSize(0);
|
||||
|
||||
assertThat("string").as("foo").isEmpty();
|
||||
assertThat(new StringBuilder()).as("bar").isEmpty();
|
||||
assertThat(new ArrayList<Long>()).as("etc").isEmpty();
|
||||
assertThat(new Long[1]).as("etc").isEmpty();
|
||||
|
||||
assertThat(new ArrayList<>().size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -54,4 +68,15 @@ public class Playground {
|
||||
assertThat(foo).hasSize(0);
|
||||
}
|
||||
|
||||
private void junitAssertions() {
|
||||
assertTrue(true);
|
||||
assertTrue("message", true);
|
||||
assertFalse(true);
|
||||
assertFalse("message", true);
|
||||
assertEquals(1L, 2L);
|
||||
assertEquals("message", 1L, 2L);
|
||||
assertNotEquals(1L, 2L);
|
||||
assertNotEquals("message", 1L, 2L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+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 AssertThatEnumerableIsEmptyInspectionTest : AbstractCajonTest() {
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("inspections/EnumerableIsEmpty")
|
||||
internal fun assertThat_with_hasSize_zero_can_use_isEmpty(@MyFixture myFixture: JavaCodeInsightTestFixture) {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatEnumerableIsEmptyInspection::class.java)
|
||||
myFixture.configureByFile("EnumerableIsEmptyBefore.java")
|
||||
executeQuickFixes(myFixture, Regex("Replace hasSize.*"), 4)
|
||||
myFixture.checkResultByFile("EnumerableIsEmptyAfter.java")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EnumerableIsEmpty {
|
||||
|
||||
private void enumerableIsEmpty() {
|
||||
assertThat("string").as("foo").isEmpty();
|
||||
assertThat(new StringBuilder()).as("bar").isEmpty();
|
||||
assertThat(new ArrayList<Long>()).as("etc").isEmpty();
|
||||
assertThat(new Long[1]).as("etc").isEmpty();
|
||||
|
||||
assertThat("string").as("foo").hasSize(1);
|
||||
assertThat(new StringBuilder()).as("bar").hasSize(1);
|
||||
assertThat(new ArrayList<Long>()).as("etc").hasSize(1);
|
||||
assertThat(new Long[1]).as("etc").hasSize(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EnumerableIsEmpty {
|
||||
|
||||
private void enumerableIsEmpty() {
|
||||
assertThat("string").as("foo").hasSize(0);
|
||||
assertThat(new StringBuilder()).as("bar").hasSize(0 + 0);
|
||||
assertThat(new ArrayList<Long>()).as("etc").hasSize(10 / 100);
|
||||
assertThat(new Long[1]).as("etc").hasSize(1 - 1);
|
||||
|
||||
assertThat("string").as("foo").hasSize(1);
|
||||
assertThat(new StringBuilder()).as("bar").hasSize(1);
|
||||
assertThat(new ArrayList<Long>()).as("etc").hasSize(1);
|
||||
assertThat(new Long[1]).as("etc").hasSize(1);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class StringIsEmpty {
|
||||
assertThat(string).as("bar").hasSize(0);
|
||||
|
||||
assertThat(stringBuilder).isEqualTo("foo");
|
||||
assertThat(stringBuilder).as("foo").isEqualTo("");
|
||||
assertThat(stringBuilder).as("foo").isEqualTo("" + "");
|
||||
assertThat(stringBuilder).as("bar").hasSize(0);
|
||||
|
||||
assertThat(new Object()).isEqualTo("");
|
||||
|
||||
Reference in New Issue
Block a user