diff --git a/qulice-pmd/src/test/java/com/qulice/pmd/UseStringIsEmptyRuleTest.java b/qulice-pmd/src/test/java/com/qulice/pmd/UseStringIsEmptyRuleTest.java index 4a1fb3081..4cc9723b6 100644 --- a/qulice-pmd/src/test/java/com/qulice/pmd/UseStringIsEmptyRuleTest.java +++ b/qulice-pmd/src/test/java/com/qulice/pmd/UseStringIsEmptyRuleTest.java @@ -33,6 +33,9 @@ import org.hamcrest.core.CombinableMatcher; import org.hamcrest.core.IsEqual; import org.hamcrest.core.StringContains; +import org.hamcrest.text.IsEmptyString; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -72,6 +75,21 @@ public void detectLengthComparisons(final String file) throws Exception { ).validate(); } + /** + * UseStringIsEmpty not detect when used String[].length, when checking for + * empty string. + * @throws Exception If something goes wrong. + */ + @Disabled + @Test + public void notDetectOnArrayOfStrings() throws Exception { + new PmdAssert( + "ArrayOfStringsLengthGreaterThanZero.java", + new IsEqual<>(true), + new IsEmptyString() + ).validate(); + } + /** * Constructs StringContains matcher for error message. * @param file File name. diff --git a/qulice-pmd/src/test/resources/com/qulice/pmd/ArrayOfStringsLengthGreaterThanZero.java b/qulice-pmd/src/test/resources/com/qulice/pmd/ArrayOfStringsLengthGreaterThanZero.java new file mode 100644 index 000000000..2816ae348 --- /dev/null +++ b/qulice-pmd/src/test/resources/com/qulice/pmd/ArrayOfStringsLengthGreaterThanZero.java @@ -0,0 +1,27 @@ +package foo; + +public final class ArrayOfStringsLengthGreaterThanZero { + + private final String[] strings; + + public ArrayOfStringsLengthGreaterThanZero(final String... args) { + this.strings = args.clone(); + } + + public String[] args() { + return this.strings.clone(); + } + + public boolean arrayFromArgs(final String... args) { + return args.length > 0; + } + + public boolean arrayFromField() { + return this.strings.length > 0; + } + + public boolean arrayFromMethod() { + return this.args().length > 0; + } + +}