New AssertThatStringExpression that will move isEmpty(), equals(), equalsIgnoreCase(), contains(), startsWith(), and endsWith() out of actual expression. Bumped intellij-plugin to latest version.

This commit is contained in:
2019-04-19 19:33:14 +02:00
parent faeb509797
commit da83f7f101
15 changed files with 336 additions and 75 deletions
@@ -26,7 +26,7 @@ internal class AssertThatGuavaOptionalInspectionTest : AbstractCajonTest() {
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isTrue() with isPresent()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isFalse() with isAbsent()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isEqualTo() with contains()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap expected expression and replace isEqualTo() with contains()"), 6)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove unwrapping of expected expression and replace isEqualTo() with contains()"), 6)
myFixture.checkResultByFile("AssertThatGuavaOptionalAfter.java")
}
}
@@ -22,7 +22,7 @@ internal class AssertThatJava8OptionalInspectionTest : AbstractCajonTest() {
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isNotPresent()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isPresent()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isFalse() with isNotPresent()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap expected expression and replace isEqualTo() with contains()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove unwrapping of expected expression and replace isEqualTo() with contains()"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isEqualTo() with contains()"), 1)
executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap actual expression and replace isSameAs() with containsSame()"), 1)
myFixture.checkResultByFile("AssertThatJava8OptionalAfter.java")
@@ -0,0 +1,34 @@
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 AssertThatStringExpressionInspectionTest : AbstractCajonTest() {
@Test
@TestDataSubPath("inspections/StringExpression")
internal fun assertThat_with_certain_String_methods(@MyFixture myFixture: JavaCodeInsightTestFixture) {
runTest {
myFixture.enableInspections(AssertThatStringExpressionInspection::class.java)
myFixture.configureByFile("StringExpressionBefore.java")
executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of expected expression and use assertThat().isEmpty() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove equals() of expected expression and use assertThat().isEqualTo() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove equalsIgnoreCase() of expected expression and use assertThat().isEqualToIgnoringCase() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove contentEquals() of expected expression and use assertThat().isEqualTo() instead"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of expected expression and use assertThat().contains() instead"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove startsWith() of expected expression and use assertThat().startsWith() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove endsWith() of expected expression and use assertThat().endsWith() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of expected expression and use assertThat().isNotEmpty() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove equals() of expected expression and use assertThat().isNotEqualTo() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove equalsIgnoreCase() of expected expression and use assertThat().isNotEqualToIgnoringCase() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove contentEquals() of expected expression and use assertThat().isNotEqualTo() instead"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of expected expression and use assertThat().doesNotContain() instead"), 4)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove startsWith() of expected expression and use assertThat().doesNotStartWith() instead"), 2)
executeQuickFixes(myFixture, Regex.fromLiteral("Remove endsWith() of expected expression and use assertThat().doesNotEndWith() instead"), 2)
myFixture.checkResultByFile("StringExpressionAfter.java")
}
}
}
@@ -0,0 +1,47 @@
import static org.assertj.core.api.Assertions.assertThat;
public class StringExpression {
private void stringExpression() {
String string = "string";
StringBuilder stringBuilder = new StringBuilder();
assertThat(string).isEmpty();
assertThat(string).isEmpty();
assertThat(string).isEqualTo("foo");
assertThat(string).isEqualTo("foo");
assertThat(string).isEqualToIgnoringCase("foo");
assertThat(string).isEqualToIgnoringCase("foo");
assertThat(string).isEqualTo("foo");
assertThat(string).isEqualTo("foo");
assertThat(string).isEqualTo(stringBuilder);
assertThat(string).isEqualTo(stringBuilder);
assertThat(string).contains("foo");
assertThat(string).contains("foo");
assertThat(string).contains(stringBuilder);
assertThat(string).contains(stringBuilder);
assertThat(string).startsWith("foo");
assertThat(string).startsWith("foo");
assertThat(string).endsWith("foo");
assertThat(string).endsWith("foo");
assertThat(string).isNotEmpty();
assertThat(string).isNotEmpty();
assertThat(string).isNotEqualTo("foo");
assertThat(string).isNotEqualTo("foo");
assertThat(string).isNotEqualToIgnoringCase("foo");
assertThat(string).isNotEqualToIgnoringCase("foo");
assertThat(string).isNotEqualTo("foo");
assertThat(string).isNotEqualTo("foo");
assertThat(string).isNotEqualTo(stringBuilder);
assertThat(string).isNotEqualTo(stringBuilder);
assertThat(string).doesNotContain("foo");
assertThat(string).doesNotContain("foo");
assertThat(string).doesNotContain(stringBuilder);
assertThat(string).doesNotContain(stringBuilder);
assertThat(string).doesNotStartWith("foo");
assertThat(string).doesNotStartWith("foo");
assertThat(string).doesNotEndWith("foo");
assertThat(string).doesNotEndWith("foo");
}
}
@@ -0,0 +1,47 @@
import static org.assertj.core.api.Assertions.assertThat;
public class StringExpression {
private void stringExpression() {
String string = "string";
StringBuilder stringBuilder = new StringBuilder();
assertThat(string.isEmpty()).isEqualTo(true);
assertThat(string.isEmpty()).isTrue();
assertThat(string.equals("foo")).isEqualTo(true);
assertThat(string.equals("foo")).isTrue();
assertThat(string.equalsIgnoreCase("foo")).isEqualTo(true);
assertThat(string.equalsIgnoreCase("foo")).isTrue();
assertThat(string.contentEquals("foo")).isEqualTo(true);
assertThat(string.contentEquals("foo")).isTrue();
assertThat(string.contentEquals(stringBuilder)).isTrue();
assertThat(string.contentEquals(stringBuilder)).isEqualTo(true);
assertThat(string.contains("foo")).isEqualTo(true);
assertThat(string.contains("foo")).isTrue();
assertThat(string.contains(stringBuilder)).isEqualTo(true);
assertThat(string.contains(stringBuilder)).isTrue();
assertThat(string.startsWith("foo")).isEqualTo(true);
assertThat(string.startsWith("foo")).isTrue();
assertThat(string.endsWith("foo")).isEqualTo(true);
assertThat(string.endsWith("foo")).isTrue();
assertThat(string.isEmpty()).isEqualTo(false);
assertThat(string.isEmpty()).isFalse();
assertThat(string.equals("foo")).isEqualTo(false);
assertThat(string.equals("foo")).isFalse();
assertThat(string.equalsIgnoreCase("foo")).isEqualTo(false);
assertThat(string.equalsIgnoreCase("foo")).isFalse();
assertThat(string.contentEquals("foo")).isEqualTo(false);
assertThat(string.contentEquals("foo")).isFalse();
assertThat(string.contentEquals(stringBuilder)).isFalse();
assertThat(string.contentEquals(stringBuilder)).isEqualTo(false);
assertThat(string.contains("foo")).isEqualTo(false);
assertThat(string.contains("foo")).isFalse();
assertThat(string.contains(stringBuilder)).isEqualTo(false);
assertThat(string.contains(stringBuilder)).isFalse();
assertThat(string.startsWith("foo")).isEqualTo(false);
assertThat(string.startsWith("foo")).isFalse();
assertThat(string.endsWith("foo")).isEqualTo(false);
assertThat(string.endsWith("foo")).isFalse();
}
}