diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJRules.java index c2e2f1415c..8e24755f00 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJRules.java @@ -264,6 +264,7 @@ void before(Iterable iterable) { Refaster.anyOf( assertThat(iterable).hasSize(0), assertThat(iterable.iterator().hasNext()).isFalse(), + assertThat(iterable.iterator()).isExhausted(), assertThat(Iterables.size(iterable)).isEqualTo(0L), assertThat(Iterables.size(iterable)).isNotPositive()); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java index 4143884ea6..af4e03a351 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java @@ -12,6 +12,7 @@ import java.nio.file.Files; import java.nio.file.Path; import org.assertj.core.api.AbstractAssert; +import org.assertj.core.api.AbstractBooleanAssert; import org.assertj.core.api.AbstractStringAssert; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; @@ -69,6 +70,32 @@ static final class AssertThatStringIsNotEmpty { } } + static final class AssertThatStringContains { + @BeforeTemplate + AbstractBooleanAssert before(String string, String substring) { + return assertThat(string.contains(substring)).isTrue(); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractStringAssert after(String string, String substring) { + return assertThat(string).contains(substring); + } + } + + static final class AssertThatStringDoesNotContain { + @BeforeTemplate + AbstractBooleanAssert before(String string, String substring) { + return assertThat(string.contains(substring)).isFalse(); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractStringAssert after(String string, String substring) { + return assertThat(string).doesNotContain(substring); + } + } + static final class AssertThatMatches { @BeforeTemplate AbstractAssert before(String string, String regex) { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java index 8c0d927860..a19b077988 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java @@ -33,6 +33,14 @@ AbstractStringAssert testAbstractStringAssertStringIsNotEmpty() { return assertThat("foo".isEmpty()).isFalse(); } + AbstractAssert testAssertThatStringContains() { + return assertThat("foo".contains("bar")).isTrue(); + } + + AbstractAssert testAssertThatStringDoesNotContain() { + return assertThat("foo".contains("bar")).isFalse(); + } + AbstractAssert testAssertThatMatches() { return assertThat("foo".matches(".*")).isTrue(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java index c9d019b21a..7938bf163d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java @@ -34,6 +34,14 @@ AbstractStringAssert testAbstractStringAssertStringIsNotEmpty() { return assertThat("foo").isNotEmpty(); } + AbstractAssert testAssertThatStringContains() { + return assertThat("foo").contains("bar"); + } + + AbstractAssert testAssertThatStringDoesNotContain() { + return assertThat("foo").doesNotContain("bar"); + } + AbstractAssert testAssertThatMatches() { return assertThat("foo").matches(".*"); }