Merged AssertThatObjectIsNull and AssertThatObjectIsNotNull to AssertThatObjectIsNullOrNotNull.
Extended tests to be more explicit regarding the expected quick fix messages.
This commit is contained in:
@@ -61,7 +61,7 @@ abstract class AbstractCajonTest {
|
||||
|
||||
protected fun executeQuickFixes(myFixture: JavaCodeInsightTestFixture, regex: Regex, expectedFixes: Int) {
|
||||
val quickfixes = myFixture.getAllQuickFixes().filter { it.familyName.matches(regex) }
|
||||
assertThat(quickfixes).hasSize(expectedFixes)
|
||||
assertThat(quickfixes).`as`("Fixes matched by $regex: ${myFixture.getAllQuickFixes().map { it.familyName }}").hasSize(expectedFixes)
|
||||
quickfixes.forEach(myFixture::launchAction)
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -14,7 +14,10 @@ internal class AssertThatBooleanIsTrueOrFalseInspectionTest : AbstractCajonTest(
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatBooleanIsTrueOrFalseInspection::class.java)
|
||||
myFixture.configureByFile("BooleanIsTrueOrFalseBefore.java")
|
||||
executeQuickFixes(myFixture, Regex("Replace is.*"), 17)
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ internal class AssertThatEnumerableIsEmptyInspectionTest : AbstractCajonTest() {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatEnumerableIsEmptyInspection::class.java)
|
||||
myFixture.configureByFile("EnumerableIsEmptyBefore.java")
|
||||
executeQuickFixes(myFixture, Regex("Replace hasSize.*"), 4)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 4)
|
||||
myFixture.checkResultByFile("EnumerableIsEmptyAfter.java")
|
||||
}
|
||||
}
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
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 AssertThatObjectIsNotNullInspectionTest : AbstractCajonTest() {
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("inspections/ObjectIsNotNull")
|
||||
internal fun assertThat_with_isNotEqualTo_null_can_use_isNotNull(@MyFixture myFixture: JavaCodeInsightTestFixture) {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatObjectIsNotNullInspection::class.java)
|
||||
myFixture.configureByFile("ObjectIsNotNullBefore.java")
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isNotNull()"), 3)
|
||||
myFixture.checkResultByFile("ObjectIsNotNullAfter.java")
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -6,16 +6,17 @@ import de.platon42.intellij.jupiter.TestDataSubPath
|
||||
import de.platon42.intellij.plugins.cajon.AbstractCajonTest
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class AssertThatObjectIsNullInspectionTest : AbstractCajonTest() {
|
||||
internal class AssertThatObjectIsNullOrNotNullInspectionTest : AbstractCajonTest() {
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("inspections/ObjectIsNull")
|
||||
@TestDataSubPath("inspections/ObjectIsNullOrNotNull")
|
||||
internal fun assertThat_with_isEqualTo_null_can_use_isNull(@MyFixture myFixture: JavaCodeInsightTestFixture) {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatObjectIsNullInspection::class.java)
|
||||
myFixture.configureByFile("ObjectIsNullBefore.java")
|
||||
myFixture.enableInspections(AssertThatObjectIsNullOrNotNullInspection::class.java)
|
||||
myFixture.configureByFile("ObjectIsNullOrNotNullBefore.java")
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isNull()"), 3)
|
||||
myFixture.checkResultByFile("ObjectIsNullAfter.java")
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isNotNull()"), 3)
|
||||
myFixture.checkResultByFile("ObjectIsNullOrNotNullAfter.java")
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -14,7 +14,19 @@ internal class AssertThatSizeInspectionTest : AbstractCajonTest() {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatSizeInspection::class.java)
|
||||
myFixture.configureByFile("AssertThatSizeBefore.java")
|
||||
executeQuickFixes(myFixture, Regex("Replace .*"), 28)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isZero() with isEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotZero() with isNotEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThan() with isNotEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThanOrEqualTo() with isNotEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThan() with isEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThanOrEqualTo() with isEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with hasSameSizeAs()"), 4)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with hasSize()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThan() with hasSizeGreaterThan()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThanOrEqualTo() with hasSizeGreaterThanOrEqualTo()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThan() with hasSizeLessThan()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThanOrEqualTo() with hasSizeLessThanOrEqualTo()"), 2)
|
||||
myFixture.checkResultByFile("AssertThatSizeAfter.java")
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -14,7 +14,8 @@ internal class AssertThatStringIsEmptyInspectionTest : AbstractCajonTest() {
|
||||
runTest {
|
||||
myFixture.enableInspections(AssertThatStringIsEmptyInspection::class.java)
|
||||
myFixture.configureByFile("StringIsEmptyBefore.java")
|
||||
executeQuickFixes(myFixture, Regex("Replace .*"), 4)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 2)
|
||||
executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 2)
|
||||
myFixture.checkResultByFile("StringIsEmptyAfter.java")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ObjectIsNotNull {
|
||||
|
||||
private void objectIsNotNull() {
|
||||
assertThat("").isNotNull();
|
||||
assertThat("").as("nah").isNotNull();
|
||||
assertThat(new Object).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ObjectIsNotNull {
|
||||
|
||||
private void objectIsNotNull() {
|
||||
assertThat("").isNotEqualTo(null);
|
||||
assertThat("").as("nah").isNotEqualTo(null);
|
||||
assertThat(new Object).isNotEqualTo(null);
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -5,6 +5,10 @@ public class ObjectIsNull {
|
||||
private void objectIsNull() {
|
||||
assertThat("").isNull();
|
||||
assertThat("").as("nah").isNull();
|
||||
assertThat(new Object).isNull();
|
||||
assertThat(new Object()).isNull();
|
||||
|
||||
assertThat("").isNotNull();
|
||||
assertThat("").as("nah").isNotNull();
|
||||
assertThat(new Object()).isNotNull();
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -5,6 +5,10 @@ public class ObjectIsNull {
|
||||
private void objectIsNull() {
|
||||
assertThat("").isEqualTo(null);
|
||||
assertThat("").as("nah").isEqualTo(null);
|
||||
assertThat(new Object).isEqualTo(null);
|
||||
assertThat(new Object()).isEqualTo(null);
|
||||
|
||||
assertThat("").isNotEqualTo(null);
|
||||
assertThat("").as("nah").isNotEqualTo(null);
|
||||
assertThat(new Object()).isNotEqualTo(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user