Fixed isEmpty() for enumerables and strings and isNull() for object conversions to be applied only if it is the terminal method call as isEmpty() and isNull() return void.

This commit is contained in:
2019-05-01 13:15:31 +02:00
parent e55acf9c74
commit 362c4210a5
14 changed files with 27 additions and 11 deletions
@@ -14,7 +14,7 @@ internal class AssertThatEnumerableIsEmptyInspectionTest : AbstractCajonTest() {
runTest {
myFixture.enableInspections(AssertThatEnumerableIsEmptyInspection::class.java)
myFixture.configureByFile("EnumerableIsEmptyBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 5)
myFixture.checkResultByFile("EnumerableIsEmptyAfter.java")
}
}
@@ -15,7 +15,7 @@ internal class AssertThatObjectIsNullOrNotNullInspectionTest : AbstractCajonTest
myFixture.enableInspections(AssertThatObjectIsNullOrNotNullInspection::class.java)
myFixture.configureByFile("ObjectIsNullOrNotNullBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isNull()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isNotNull()"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isNotNull()"), 5)
myFixture.checkResultByFile("ObjectIsNullOrNotNullAfter.java")
}
}
@@ -14,8 +14,8 @@ internal class AssertThatStringIsEmptyInspectionTest : AbstractCajonTest() {
runTest {
myFixture.enableInspections(AssertThatStringIsEmptyInspection::class.java)
myFixture.configureByFile("StringIsEmptyBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 3)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 3)
myFixture.checkResultByFile("StringIsEmptyAfter.java")
}
}
@@ -14,5 +14,7 @@ public class EnumerableIsEmpty {
assertThat(new StringBuilder()).as("bar").hasSize(1);
assertThat(new ArrayList<Long>()).as("etc").hasSize(1);
assertThat(new Long[1]).as("etc").hasSize(1);
assertThat("string").as("foo").hasSize(0).hasSameSizeAs("foo").isEmpty();
}
}
@@ -14,5 +14,7 @@ public class EnumerableIsEmpty {
assertThat(new StringBuilder()).as("bar").hasSize(1);
assertThat(new ArrayList<Long>()).as("etc").hasSize(1);
assertThat(new Long[1]).as("etc").hasSize(1);
assertThat("string").as("foo").hasSize(0).hasSameSizeAs("foo").hasSize(0);
}
}
@@ -12,5 +12,6 @@ public class ObjectIsNull {
assertThat(new Object()).isNotNull();
assertThat(new Object()).as("foo").isNotNull().as("bar").isEqualTo(new Object()).as("etc").isNull();
assertThat(new Object()).as("foo").isEqualTo(null).as("bar").isEqualTo(new Object()).as("etc").isNotNull();
}
}
@@ -12,5 +12,6 @@ public class ObjectIsNull {
assertThat(new Object()).isNotEqualTo(null);
assertThat(new Object()).as("foo").isNotEqualTo(null).as("bar").isEqualTo(new Object()).as("etc").isEqualTo(null);
assertThat(new Object()).as("foo").isEqualTo(null).as("bar").isEqualTo(new Object()).as("etc").isNotEqualTo(null);
}
}
@@ -15,5 +15,8 @@ public class StringIsEmpty {
assertThat(stringBuilder).as("bar").isEmpty();
assertThat(new Object()).isEqualTo("");
assertThat(string).as("foo").isEqualTo("").as("bar").hasSize(0).hasSameSizeAs("foo").isEmpty();
assertThat(string).as("foo").isEqualTo("").as("bar").hasSize(0).hasSameSizeAs("foo").isEmpty();
}
}
@@ -15,5 +15,8 @@ public class StringIsEmpty {
assertThat(stringBuilder).as("bar").hasSize(0);
assertThat(new Object()).isEqualTo("");
assertThat(string).as("foo").isEqualTo("").as("bar").hasSize(0).hasSameSizeAs("foo").isEqualTo("");
assertThat(string).as("foo").isEqualTo("").as("bar").hasSize(0).hasSameSizeAs("foo").hasSize(0);
}
}