From ffebbf4c8c98becde4dbad8dc2241d84f8f1a145 Mon Sep 17 00:00:00 2001 From: komatzu1337 Date: Thu, 15 May 2025 03:59:24 +0300 Subject: [PATCH 1/5] Add extractMatches method implementation --- .../org/apache/commons/lang3/RegExUtils.java | 19 +++++++++++++++++++ .../apache/commons/lang3/RegExUtilsTest.java | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/org/apache/commons/lang3/RegExUtils.java b/src/main/java/org/apache/commons/lang3/RegExUtils.java index dc3351d03f6..6b8255cca4a 100644 --- a/src/main/java/org/apache/commons/lang3/RegExUtils.java +++ b/src/main/java/org/apache/commons/lang3/RegExUtils.java @@ -16,6 +16,8 @@ */ package org.apache.commons.lang3; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -751,4 +753,21 @@ private static String toStringOrNull(final CharSequence text) { public RegExUtils() { // empty } + + /** + * Extracts all matches of a regular expression pattern from the text. + * + * @param text the text to search in, may be null (returns empty list) + * @param pattern the compiled pattern, may be null (returns empty list) + * @return a list of all matches, never null + * @since 4.1.0 + */ + public static List extractMatches(final String text, final Pattern pattern) { + final Matcher matcher = pattern.matcher(text); + final List matches = new ArrayList<>(); + while (matcher.find()) { + matches.add(matcher.group()); + } + return matches; + } } diff --git a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java index af3ee9df0a3..0085b2d011e 100644 --- a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java @@ -21,6 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.Arrays; +import java.util.List; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -379,4 +381,20 @@ public void testReplacePatternDeprecated() { assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replacePattern("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2")); } + @Test + public void testExtractMatches() { + final List matches = RegExUtils.extractMatches("a1b2c3", Pattern.compile("\\d")); + assertEquals(Arrays.asList("1", "2", "3"), matches); + } + + @Test + public void testExtractMatches_NoMatches() { + assertTrue(RegExUtils.extractMatches("abc", Pattern.compile("\\d")).isEmpty()); + } + + @Test + public void testExtractMatches_NullInput() { + assertTrue(RegExUtils.extractMatches(null, Pattern.compile("\\d")).isEmpty()); + } + } From 827baf082caf2082324c661b2ffd567c13d38af7 Mon Sep 17 00:00:00 2001 From: komatzu1337 Date: Thu, 15 May 2025 06:59:11 +0300 Subject: [PATCH 2/5] Now throws IllegalArgumentException with clear messages for null Supports both String and CharSequence Provides both List and String[] return Added regex-string variant All returned collections are unmodifiable Never returns null (empty collections for null) Improved documentation --- .../org/apache/commons/lang3/RegExUtils.java | 73 +++++++++++++++---- .../apache/commons/lang3/RegExUtilsTest.java | 24 +----- 2 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/RegExUtils.java b/src/main/java/org/apache/commons/lang3/RegExUtils.java index 6b8255cca4a..8ef30c1398c 100644 --- a/src/main/java/org/apache/commons/lang3/RegExUtils.java +++ b/src/main/java/org/apache/commons/lang3/RegExUtils.java @@ -17,10 +17,12 @@ package org.apache.commons.lang3; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; /** * Helpers to process Strings using regular expressions. @@ -754,20 +756,63 @@ public RegExUtils() { // empty } - /** - * Extracts all matches of a regular expression pattern from the text. - * - * @param text the text to search in, may be null (returns empty list) - * @param pattern the compiled pattern, may be null (returns empty list) - * @return a list of all matches, never null - * @since 4.1.0 - */ - public static List extractMatches(final String text, final Pattern pattern) { - final Matcher matcher = pattern.matcher(text); - final List matches = new ArrayList<>(); - while (matcher.find()) { - matches.add(matcher.group()); + + public class MatchFinder { + + /** + * Finds all matches in the given text according to the specified pattern. + * + * @param text the text to search for matches + * @param pattern the pattern to search for + * @return a list of found matches + * @throws IllegalArgumentException if text or pattern is null + */ + public List findMatches(CharSequence text, Pattern pattern) { + if (text == null) + throw new IllegalArgumentException("Text must not be null"); + + if (pattern == null) + throw new IllegalArgumentException("Pattern must not be null"); + + List matches = new ArrayList<>(); + Matcher matcher = pattern.matcher(text); + + while (matcher.find()) { + matches.add(matcher.group()); + } + + return Collections.unmodifiableList(matches); // return an unmodifiable list + } + + /** + * Finds all matches in the given text according to the specified pattern. + * + * @param text the text to search for matches + * @param pattern the pattern to search for + * @return a list of found matches + * @throws IllegalArgumentException if text or pattern is null + */ + public List findMatches(String text, Pattern pattern) { + return findMatches((CharSequence) text, pattern); + } + + /** + * Finds all matches in the given text according to the specified pattern + * and returns them as an array of strings. + * + * @param text the text to search for matches (throws IllegalArgumentException if null) + * @param regex the regular expression pattern (throws IllegalArgumentException if null or invalid) + * @return an array of found matches (never null) + * @throws IllegalArgumentException if text or regex is null + * @throws PatternSyntaxException if the regex syntax is invalid + */ + public String[] findMatchesAsArray(CharSequence text, String regex) { + if (regex == null) { + throw new IllegalArgumentException("Regex must not be null"); + } + Pattern pattern = Pattern.compile(regex); + List matches = findMatches(text, pattern); + return matches.toArray(new String[0]); } - return matches; } } diff --git a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java index 0085b2d011e..95e3f943f40 100644 --- a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java @@ -16,11 +16,6 @@ */ package org.apache.commons.lang3; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -28,6 +23,8 @@ import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + /** * Tests {@link RegExUtils}. */ @@ -380,21 +377,4 @@ public void testReplacePatternDeprecated() { assertEquals("ABC123", RegExUtils.replacePattern("ABCabc123", "[^A-Z0-9]+", "")); assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replacePattern("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2")); } - - @Test - public void testExtractMatches() { - final List matches = RegExUtils.extractMatches("a1b2c3", Pattern.compile("\\d")); - assertEquals(Arrays.asList("1", "2", "3"), matches); - } - - @Test - public void testExtractMatches_NoMatches() { - assertTrue(RegExUtils.extractMatches("abc", Pattern.compile("\\d")).isEmpty()); - } - - @Test - public void testExtractMatches_NullInput() { - assertTrue(RegExUtils.extractMatches(null, Pattern.compile("\\d")).isEmpty()); - } - } From 8b27f2e8b3159bb5c05c3996fd2f551b76d964fc Mon Sep 17 00:00:00 2001 From: komatzu1337 Date: Sat, 17 May 2025 00:09:51 +0300 Subject: [PATCH 3/5] added tests class MatchFinder was removed now returns empty List if pattern or text null {} added on if, so RegExUtils will pass checks --- .../org/apache/commons/lang3/RegExUtils.java | 89 ++++++++--------- .../apache/commons/lang3/RegExUtilsTest.java | 99 +++++++++++++++++++ 2 files changed, 141 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/RegExUtils.java b/src/main/java/org/apache/commons/lang3/RegExUtils.java index 8ef30c1398c..13079eec672 100644 --- a/src/main/java/org/apache/commons/lang3/RegExUtils.java +++ b/src/main/java/org/apache/commons/lang3/RegExUtils.java @@ -757,62 +757,57 @@ public RegExUtils() { } - public class MatchFinder { - - /** - * Finds all matches in the given text according to the specified pattern. - * - * @param text the text to search for matches - * @param pattern the pattern to search for - * @return a list of found matches - * @throws IllegalArgumentException if text or pattern is null - */ - public List findMatches(CharSequence text, Pattern pattern) { - if (text == null) - throw new IllegalArgumentException("Text must not be null"); + /** + * Finds all matches in the given text according to the specified pattern. + * + * @param text the text to search for matches + * @param pattern the pattern to search for + * @return a list of found matches; returns an empty List if text or pattern is null + */ + public List findMatches(CharSequence text, Pattern pattern) { + if (text == null || pattern == null){ + return Collections.emptyList(); + } - if (pattern == null) - throw new IllegalArgumentException("Pattern must not be null"); + List matches = new ArrayList<>(); + Matcher matcher = pattern.matcher(text); - List matches = new ArrayList<>(); - Matcher matcher = pattern.matcher(text); + while (matcher.find()) { + matches.add(matcher.group()); + } - while (matcher.find()) { - matches.add(matcher.group()); - } + return Collections.unmodifiableList(matches); + } - return Collections.unmodifiableList(matches); // return an unmodifiable list - } + /** + * Finds all matches in the given text according to the specified pattern. + * + * @param text the text to search for matches + * @param pattern the pattern to search for + * @return a list of found matches + */ + public List findMatches(String text, Pattern pattern) { + return findMatches((CharSequence) text, pattern); + } - /** - * Finds all matches in the given text according to the specified pattern. - * - * @param text the text to search for matches - * @param pattern the pattern to search for - * @return a list of found matches - * @throws IllegalArgumentException if text or pattern is null - */ - public List findMatches(String text, Pattern pattern) { - return findMatches((CharSequence) text, pattern); + /** + * Finds all matches in the given text according to the specified pattern + * and returns them as an array of strings. + * + * @param text the text to search for matches + * @param regex the regular expression pattern + * @return an array of found matches; returns an empty array if text or regex is null + */ + public String[] findMatchesAsArray(CharSequence text, String regex) { + if (text == null ||regex == null){ + return new String[0]; } - - /** - * Finds all matches in the given text according to the specified pattern - * and returns them as an array of strings. - * - * @param text the text to search for matches (throws IllegalArgumentException if null) - * @param regex the regular expression pattern (throws IllegalArgumentException if null or invalid) - * @return an array of found matches (never null) - * @throws IllegalArgumentException if text or regex is null - * @throws PatternSyntaxException if the regex syntax is invalid - */ - public String[] findMatchesAsArray(CharSequence text, String regex) { - if (regex == null) { - throw new IllegalArgumentException("Regex must not be null"); - } + try { Pattern pattern = Pattern.compile(regex); List matches = findMatches(text, pattern); return matches.toArray(new String[0]); + }catch (PatternSyntaxException e){ + return new String[0]; } } } diff --git a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java index 95e3f943f40..b8578d6ce80 100644 --- a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java @@ -16,13 +16,17 @@ */ package org.apache.commons.lang3; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import javax.annotation.RegEx; + import static org.junit.jupiter.api.Assertions.*; /** @@ -377,4 +381,99 @@ public void testReplacePatternDeprecated() { assertEquals("ABC123", RegExUtils.replacePattern("ABCabc123", "[^A-Z0-9]+", "")); assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replacePattern("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2")); } + + private RegExUtils utils; + + @BeforeEach + void setUp() { + utils = new RegExUtils(); + } + + @Test + public void testFindMultipleMatches() { + Pattern pattern = Pattern.compile("\\d+"); + List result = utils.findMatches("asd 123 fgd 456 zxc", pattern); + assertEquals(Arrays.asList("123", "456"), result); + } + + @Test + public void testFindNoMatches() { + Pattern pattern = Pattern.compile("\\d+"); + List result = utils.findMatches("asd zxc", pattern); + assertTrue(result.isEmpty()); + } + + @Test + void testFindMatchesWhenTextIsEmpty() { + String[] result = utils.findMatchesAsArray("", "\\w+"); + assertArrayEquals(new String[0], result); + } +// @Test +// public void testShouldReturnArrayList() { +// Pattern pattern = Pattern.compile("\\w+"); +// List result = utils.findMatches("test", pattern); +// assertEquals(Arrays.asList("test"), result); +// assertTrue(result instanceof ArrayList); +// } + + @Test + public void testFindMatchesWhenTextIsNull() { + Pattern pattern = Pattern.compile("test"); + List result = utils.findMatches(null, pattern); + assert (result).isEmpty(); + } + + @Test + public void testFindMatchesWhenPatternIsNull() { + List result = utils.findMatches("test", null); + assertTrue(result.isEmpty()); + } + + @Test + public void testFindMatchesWithEmptyText() { + Pattern pattern = Pattern.compile("\\d+"); + List result = utils.findMatches("", pattern); + assertTrue(result.isEmpty()); + } + + @Test + public void testFindMultipleMatchesAsArray() { + String[] result = utils.findMatchesAsArray("test 123 test", "\\w+"); + assertArrayEquals(new String[]{"test", "123", "test"}, result); + } + + @Test + void testFindMatchesAsArrayWhenNoMatches() { + String[] result = utils.findMatchesAsArray("abc", "\\d"); + assertArrayEquals(new String[0], result); + } + + @Test + void testFindMatchesAsArrayWhenTextIsNull() { + String[] result = utils.findMatchesAsArray(null, "\\w+"); + assertArrayEquals(new String[0], result); + } + + @Test + void testFindMatchesAsArrayWhenTextIsEmpty() { + String[] result = utils.findMatchesAsArray("", "\\w+"); + assertArrayEquals(new String[0], result); + } + + @Test + void testFindMatchesAsArrayWithInvalidRegex() { + String[] result = utils.findMatchesAsArray("text", "[a-z"); + assertArrayEquals(new String[0], result); + } + + @Test + public void testReturnedListIsUnmodifiable() { + Pattern pattern = Pattern.compile("\\w+"); + List result = utils.findMatches("test", pattern); + + try { + result.add("should fail"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) {} + } } From 68422077f57ad9c42099ea16342275dd23670276 Mon Sep 17 00:00:00 2001 From: komatzu1337 Date: Sat, 17 May 2025 14:08:15 +0300 Subject: [PATCH 4/5] Method findMatchesModifiable added tests added public List findMatches(String text, Pattern pattern) is removed --- .../org/apache/commons/lang3/RegExUtils.java | 34 +++++++----- .../apache/commons/lang3/RegExUtilsTest.java | 52 ++++++++++++++++++- 2 files changed, 72 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/RegExUtils.java b/src/main/java/org/apache/commons/lang3/RegExUtils.java index 13079eec672..d361b81ddd7 100644 --- a/src/main/java/org/apache/commons/lang3/RegExUtils.java +++ b/src/main/java/org/apache/commons/lang3/RegExUtils.java @@ -756,13 +756,12 @@ public RegExUtils() { // empty } - /** * Finds all matches in the given text according to the specified pattern. * * @param text the text to search for matches * @param pattern the pattern to search for - * @return a list of found matches; returns an empty List if text or pattern is null + * @return an unmodifiable list of found matches; returns an empty List if text or pattern is null */ public List findMatches(CharSequence text, Pattern pattern) { if (text == null || pattern == null){ @@ -779,17 +778,6 @@ public List findMatches(CharSequence text, Pattern pattern) { return Collections.unmodifiableList(matches); } - /** - * Finds all matches in the given text according to the specified pattern. - * - * @param text the text to search for matches - * @param pattern the pattern to search for - * @return a list of found matches - */ - public List findMatches(String text, Pattern pattern) { - return findMatches((CharSequence) text, pattern); - } - /** * Finds all matches in the given text according to the specified pattern * and returns them as an array of strings. @@ -810,4 +798,24 @@ public String[] findMatchesAsArray(CharSequence text, String regex) { return new String[0]; } } + + /** + * Finds all matches in the given text according to the specified pattern + * and returns them as a modifiable ArrayList. + * + * @param text the text to search for matches + * @param pattern the pattern to search for + * @return a modifiable ArrayList of found matches; returns an empty List if text or pattern is null + */ + public List findMatchesModifiabale(CharSequence text, Pattern pattern){ + if (text == null || pattern == null){ + return new ArrayList<>(); + } + Matcher matcher = pattern.matcher(text); + List matches = new ArrayList<>(); + while (matcher.find()){ + matches.add(matcher.group()); + } + return matches; + } } diff --git a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java index b8578d6ce80..d65db76cc90 100644 --- a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.lang3; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -476,4 +475,55 @@ public void testReturnedListIsUnmodifiable() { fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) {} } + + @Test + public void testFindMultipleMatchesAsArrayList(){ + Pattern pattern = Pattern.compile("\\d+"); + List result = utils.findMatchesModifiabale("asd 123 fgd 456 zxc", pattern); + assertEquals(Arrays.asList("123", "456"), result); + } + + @Test + public void testShouldAddElementInFindMatchesModifiabale(){ + Pattern pattern = Pattern.compile("\\w+"); + List result = utils.findMatchesModifiabale("asd test 123", pattern); + result.add("text"); + assertEquals(Arrays.asList("asd", "test", "123", "text"), result); + } + + @Test + public void testShouldRemoveElementInFindMatchesModifiabale(){ + Pattern pattern = Pattern.compile("\\w+"); + List result = utils.findMatchesModifiabale("asd test 123", pattern); + result.remove("123"); + assertEquals(Arrays.asList("asd","test"), result); + } + + @Test + public void testFindNoMatchesAsArrayList() { + Pattern pattern = Pattern.compile("\\d+"); + List result = utils.findMatchesModifiabale("asd zxc", pattern); + assertTrue(result.isEmpty()); + } + + @Test + void testFindMatchesAsArrayListWhenTextIsEmpty() { + Pattern pattern = Pattern.compile("\\d+"); + Listresult = utils.findMatchesModifiabale("", pattern); + assertTrue(result.isEmpty()); + } + + @Test + void testFindMatchesAsArrayListWhenTextIsNull() { + Pattern pattern = Pattern.compile("\\d+"); + Listresult = utils.findMatchesModifiabale(null, pattern); + assertTrue(result.isEmpty()); + } + + @Test + void testFindMatchesAsArrayListWhenPatternIsNull(){ + Listresult = utils.findMatchesModifiabale("asd 123", null); + assertTrue(result.isEmpty()); + } + } From b6ed649865a6e1d891bd35fe8b1f6c2f853e6ca0 Mon Sep 17 00:00:00 2001 From: komatzu1337 Date: Sat, 17 May 2025 14:08:15 +0300 Subject: [PATCH 5/5] Method findMatchesModifiable added tests added public List findMatches(String text, Pattern pattern) is removed --- .../org/apache/commons/lang3/RegExUtils.java | 34 +++++++----- .../apache/commons/lang3/RegExUtilsTest.java | 52 ++++++++++++++++++- 2 files changed, 72 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/RegExUtils.java b/src/main/java/org/apache/commons/lang3/RegExUtils.java index 13079eec672..3b037622165 100644 --- a/src/main/java/org/apache/commons/lang3/RegExUtils.java +++ b/src/main/java/org/apache/commons/lang3/RegExUtils.java @@ -756,13 +756,12 @@ public RegExUtils() { // empty } - /** * Finds all matches in the given text according to the specified pattern. * * @param text the text to search for matches * @param pattern the pattern to search for - * @return a list of found matches; returns an empty List if text or pattern is null + * @return an unmodifiable list of found matches; returns an empty List if text or pattern is null */ public List findMatches(CharSequence text, Pattern pattern) { if (text == null || pattern == null){ @@ -779,17 +778,6 @@ public List findMatches(CharSequence text, Pattern pattern) { return Collections.unmodifiableList(matches); } - /** - * Finds all matches in the given text according to the specified pattern. - * - * @param text the text to search for matches - * @param pattern the pattern to search for - * @return a list of found matches - */ - public List findMatches(String text, Pattern pattern) { - return findMatches((CharSequence) text, pattern); - } - /** * Finds all matches in the given text according to the specified pattern * and returns them as an array of strings. @@ -810,4 +798,24 @@ public String[] findMatchesAsArray(CharSequence text, String regex) { return new String[0]; } } + + /** + * Finds all matches in the given text according to the specified pattern + * and returns them as a modifiable ArrayList. + * + * @param text the text to search for matches + * @param pattern the pattern to search for + * @return a modifiable ArrayList of found matches; returns an empty List if text or pattern is null + */ + public List findMatchesModifiable(CharSequence text, Pattern pattern){ + if (text == null || pattern == null){ + return new ArrayList<>(); + } + Matcher matcher = pattern.matcher(text); + List matches = new ArrayList<>(); + while (matcher.find()){ + matches.add(matcher.group()); + } + return matches; + } } diff --git a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java index b8578d6ce80..b24524f24ef 100644 --- a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.lang3; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -476,4 +475,55 @@ public void testReturnedListIsUnmodifiable() { fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) {} } + + @Test + public void testFindMultipleMatchesAsArrayList(){ + Pattern pattern = Pattern.compile("\\d+"); + List result = utils.findMatchesModifiable("asd 123 fgd 456 zxc", pattern); + assertEquals(Arrays.asList("123", "456"), result); + } + + @Test + public void testShouldAddElementInFindMatchesModifiabale(){ + Pattern pattern = Pattern.compile("\\w+"); + List result = utils.findMatchesModifiable("asd test 123", pattern); + result.add("text"); + assertEquals(Arrays.asList("asd", "test", "123", "text"), result); + } + + @Test + public void testShouldRemoveElementInFindMatchesModifiabale(){ + Pattern pattern = Pattern.compile("\\w+"); + List result = utils.findMatchesModifiable("asd test 123", pattern); + result.remove("123"); + assertEquals(Arrays.asList("asd","test"), result); + } + + @Test + public void testFindNoMatchesAsArrayList() { + Pattern pattern = Pattern.compile("\\d+"); + List result = utils.findMatchesModifiable("asd zxc", pattern); + assertTrue(result.isEmpty()); + } + + @Test + void testFindMatchesAsArrayListWhenTextIsEmpty() { + Pattern pattern = Pattern.compile("\\d+"); + Listresult = utils.findMatchesModifiable("", pattern); + assertTrue(result.isEmpty()); + } + + @Test + void testFindMatchesAsArrayListWhenTextIsNull() { + Pattern pattern = Pattern.compile("\\d+"); + Listresult = utils.findMatchesModifiable(null, pattern); + assertTrue(result.isEmpty()); + } + + @Test + void testFindMatchesAsArrayListWhenPatternIsNull(){ + Listresult = utils.findMatchesModifiable("asd 123", null); + assertTrue(result.isEmpty()); + } + }