Implemented AssertThatEnumerableIsEmptyInspection. Improved literal values by constant value calculation, more refactoring.

This commit is contained in:
2019-03-24 14:42:02 +01:00
parent e2ffce753c
commit 582e254195
14 changed files with 160 additions and 31 deletions
@@ -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);
}
}
@@ -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")
}
}
}