diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 617361e38..726ecc056 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -1595,6 +1595,7 @@ public class StringUtils { * StringUtils.containsAny(*, []) = false * StringUtils.containsAny("zzabyycdxx",['z','a']) = true * StringUtils.containsAny("zzabyycdxx",['b','y']) = true + * StringUtils.containsAny("zzabyycdxx",['z','y']) = true * StringUtils.containsAny("aba", ['z']) = false * * @@ -1652,6 +1653,7 @@ public class StringUtils { * StringUtils.containsAny(*, "") = false * StringUtils.containsAny("zzabyycdxx", "za") = true * StringUtils.containsAny("zzabyycdxx", "by") = true + * StringUtils.containsAny("zzabyycdxx", "zy") = true * StringUtils.containsAny("aba","z") = false * * @@ -1684,6 +1686,7 @@ public class StringUtils { * StringUtils.containsAny(*, null) = false * StringUtils.containsAny(*, []) = false * StringUtils.containsAny("abcd", "ab", "cd") = false + * StringUtils.containsAny("abcd", "ab", null) = false * StringUtils.containsAny("abc", "d", "abc") = true * * diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java index 1a1f37ad3..3a739c18d 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java @@ -117,17 +117,18 @@ public class StringUtilsEqualsIndexOfTest { public void testContainsAny_StringCharArray() { assertFalse(StringUtils.containsAny(null, (char[]) null)); assertFalse(StringUtils.containsAny(null, new char[0])); - assertFalse(StringUtils.containsAny(null, new char[] { 'a', 'b' })); + assertFalse(StringUtils.containsAny(null, 'a', 'b')); assertFalse(StringUtils.containsAny("", (char[]) null)); assertFalse(StringUtils.containsAny("", new char[0])); - assertFalse(StringUtils.containsAny("", new char[] { 'a', 'b' })); + assertFalse(StringUtils.containsAny("", 'a', 'b')); assertFalse(StringUtils.containsAny("zzabyycdxx", (char[]) null)); assertFalse(StringUtils.containsAny("zzabyycdxx", new char[0])); - assertTrue(StringUtils.containsAny("zzabyycdxx", new char[] { 'z', 'a' })); - assertTrue(StringUtils.containsAny("zzabyycdxx", new char[] { 'b', 'y' })); - assertFalse(StringUtils.containsAny("ab", new char[] { 'z' })); + assertTrue(StringUtils.containsAny("zzabyycdxx", 'z', 'a')); + assertTrue(StringUtils.containsAny("zzabyycdxx", 'b', 'y')); + assertTrue(StringUtils.containsAny("zzabyycdxx", 'z', 'y')); + assertFalse(StringUtils.containsAny("ab", 'z')); } /** @@ -179,6 +180,7 @@ public class StringUtilsEqualsIndexOfTest { assertFalse(StringUtils.containsAny("zzabyycdxx", "")); assertTrue(StringUtils.containsAny("zzabyycdxx", "za")); assertTrue(StringUtils.containsAny("zzabyycdxx", "by")); + assertTrue(StringUtils.containsAny("zzabyycdxx", "zy")); assertFalse(StringUtils.containsAny("ab", "z")); } @@ -223,9 +225,11 @@ public class StringUtilsEqualsIndexOfTest { assertFalse(StringUtils.containsAny("", new String[] { "hello" })); assertFalse(StringUtils.containsAny("hello, goodbye", (String[]) null)); assertFalse(StringUtils.containsAny("hello, goodbye", new String[0])); - assertTrue(StringUtils.containsAny("hello, goodbye", new String[] { "hello", "goodbye" })); - assertTrue(StringUtils.containsAny("hello, goodbye", new String[] { "hello", "Goodbye" })); - assertFalse(StringUtils.containsAny("hello, goodbye", new String[] { "Hello", "Goodbye" })); + assertTrue(StringUtils.containsAny("hello, goodbye", new String[]{"hello", "goodbye"})); + assertTrue(StringUtils.containsAny("hello, goodbye", new String[]{"hello", "Goodbye"})); + assertFalse(StringUtils.containsAny("hello, goodbye", new String[]{"Hello", "Goodbye"})); + assertFalse(StringUtils.containsAny("hello, goodbye", new String[]{"Hello", null})); + assertFalse(StringUtils.containsAny("hello, null", new String[] { "Hello", null })); } @Test @@ -645,17 +649,17 @@ public class StringUtilsEqualsIndexOfTest { public void testIndexOfAny_StringCharArray() { assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null)); assertEquals(-1, StringUtils.indexOfAny(null, new char[0])); - assertEquals(-1, StringUtils.indexOfAny(null, new char[] {'a','b'})); + assertEquals(-1, StringUtils.indexOfAny(null, 'a','b')); assertEquals(-1, StringUtils.indexOfAny("", (char[]) null)); assertEquals(-1, StringUtils.indexOfAny("", new char[0])); - assertEquals(-1, StringUtils.indexOfAny("", new char[] {'a','b'})); + assertEquals(-1, StringUtils.indexOfAny("", 'a','b')); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (char[]) null)); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", new char[0])); - assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", new char[] {'z','a'})); - assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", new char[] {'b','y'})); - assertEquals(-1, StringUtils.indexOfAny("ab", new char[] {'z'})); + assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", 'z','a')); + assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", 'b','y')); + assertEquals(-1, StringUtils.indexOfAny("ab", 'z')); } /** @@ -718,19 +722,19 @@ public class StringUtilsEqualsIndexOfTest { @Test public void testIndexOfAnyBut_StringCharArray() { assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null)); - assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0])); - assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[] {'a','b'})); + assertEquals(-1, StringUtils.indexOfAnyBut(null)); + assertEquals(-1, StringUtils.indexOfAnyBut(null, 'a','b')); assertEquals(-1, StringUtils.indexOfAnyBut("", (char[]) null)); - assertEquals(-1, StringUtils.indexOfAnyBut("", new char[0])); - assertEquals(-1, StringUtils.indexOfAnyBut("", new char[] {'a','b'})); + assertEquals(-1, StringUtils.indexOfAnyBut("")); + assertEquals(-1, StringUtils.indexOfAnyBut("", 'a','b')); assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (char[]) null)); - assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", new char[0])); - assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z','a'})); - assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'b','y'})); - assertEquals(-1, StringUtils.indexOfAnyBut("aba", new char[] {'a', 'b'})); - assertEquals(0, StringUtils.indexOfAnyBut("aba", new char[] {'z'})); + assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx")); + assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", 'z','a')); + assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", 'b','y')); + assertEquals(-1, StringUtils.indexOfAnyBut("aba", 'a', 'b')); + assertEquals(0, StringUtils.indexOfAnyBut("aba", 'z')); }