This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git


The following commit(s) were added to refs/heads/master by this push:
     new a839f95  100% code coverage for org.apache.commons.text.matcher.
a839f95 is described below

commit a839f9581172af78b9d87a6bae5564cd576f0071
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Jul 16 17:01:11 2020 -0400

    100% code coverage for org.apache.commons.text.matcher.
---
 .../text/matcher/AbstractStringMatcher.java        | 47 ++++++++++------------
 .../text/matcher/StringMatcherFactoryTest.java     | 41 ++++++++++++++++++-
 .../text/matcher/StringMatcherOnCharArrayTest.java |  8 ++--
 .../StringMatcherOnCharSequenceStringTest.java     |  3 +-
 4 files changed, 67 insertions(+), 32 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java 
b/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java
index 643531f..8100c6f 100644
--- a/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java
+++ b/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java
@@ -44,7 +44,8 @@ abstract class AbstractStringMatcher implements StringMatcher 
{
         /**
          * Constructs a new initialized instance.
          *
-         * @param stringMatchers Matchers in order.
+         * @param stringMatchers Matchers in order. Never null since the 
{@link StringMatcherFactory} uses the
+         *        {@link NoneMatcher} instead.
          */
         AndStringMatcher(final StringMatcher... stringMatchers) {
             this.stringMatchers = stringMatchers;
@@ -53,17 +54,15 @@ abstract class AbstractStringMatcher implements 
StringMatcher {
         @Override
         public int isMatch(final char[] buffer, final int start, final int 
bufferStart, final int bufferEnd) {
             int total = 0;
-            if (stringMatchers != null) {
-                int curStart = start;
-                for (final StringMatcher stringMatcher : stringMatchers) {
-                    if (stringMatcher != null) {
-                        final int len = stringMatcher.isMatch(buffer, 
curStart, bufferStart, bufferEnd);
-                        if (len == 0) {
-                            return 0;
-                        }
-                        total += len;
-                        curStart += len;
+            int curStart = start;
+            for (final StringMatcher stringMatcher : stringMatchers) {
+                if (stringMatcher != null) {
+                    final int len = stringMatcher.isMatch(buffer, curStart, 
bufferStart, bufferEnd);
+                    if (len == 0) {
+                        return 0;
                     }
+                    total += len;
+                    curStart += len;
                 }
             }
             return total;
@@ -72,17 +71,15 @@ abstract class AbstractStringMatcher implements 
StringMatcher {
         @Override
         public int isMatch(final CharSequence buffer, final int start, final 
int bufferStart, final int bufferEnd) {
             int total = 0;
-            if (stringMatchers != null) {
-                int curStart = start;
-                for (final StringMatcher stringMatcher : stringMatchers) {
-                    if (stringMatcher != null) {
-                        final int len = stringMatcher.isMatch(buffer, 
curStart, bufferStart, bufferEnd);
-                        if (len == 0) {
-                            return 0;
-                        }
-                        total += len;
-                        curStart += len;
+            int curStart = start;
+            for (final StringMatcher stringMatcher : stringMatchers) {
+                if (stringMatcher != null) {
+                    final int len = stringMatcher.isMatch(buffer, curStart, 
bufferStart, bufferEnd);
+                    if (len == 0) {
+                        return 0;
                     }
+                    total += len;
+                    curStart += len;
                 }
             }
             return total;
@@ -91,11 +88,9 @@ abstract class AbstractStringMatcher implements 
StringMatcher {
         @Override
         public int size() {
             int total = 0;
-            if (stringMatchers != null) {
-                for (final StringMatcher stringMatcher : stringMatchers) {
-                    if (stringMatcher != null) {
-                        total += stringMatcher.size();
-                    }
+            for (final StringMatcher stringMatcher : stringMatchers) {
+                if (stringMatcher != null) {
+                    total += stringMatcher.size();
                 }
             }
             return total;
diff --git 
a/src/test/java/org/apache/commons/text/matcher/StringMatcherFactoryTest.java 
b/src/test/java/org/apache/commons/text/matcher/StringMatcherFactoryTest.java
index 06f1e0e..057eb5c 100644
--- 
a/src/test/java/org/apache/commons/text/matcher/StringMatcherFactoryTest.java
+++ 
b/src/test/java/org/apache/commons/text/matcher/StringMatcherFactoryTest.java
@@ -27,12 +27,27 @@ import org.junit.jupiter.api.Test;
  */
 public class StringMatcherFactoryTest {
 
+    private static class StringMatcherDefaults implements StringMatcher {
+
+        @Override
+        public int isMatch(final char[] buffer, final int start, final int 
bufferStart, final int bufferEnd) {
+            return 2;
+        }
+
+    }
+
     @Test
     public void test_andMatcher() {
         
assertNotNull(StringMatcherFactory.INSTANCE.andMatcher(StringMatcherFactory.INSTANCE.charMatcher('1'),
             StringMatcherFactory.INSTANCE.stringMatcher("2")));
         assertNotNull(StringMatcherFactory.INSTANCE.andMatcher(null, 
StringMatcherFactory.INSTANCE.stringMatcher("2")));
         assertNotNull(StringMatcherFactory.INSTANCE.andMatcher(null, null));
+        StringMatcher andMatcher = StringMatcherFactory.INSTANCE.andMatcher();
+        assertNotNull(andMatcher);
+        assertEquals(0, andMatcher.size());
+        andMatcher = 
StringMatcherFactory.INSTANCE.andMatcher(StringMatcherFactory.INSTANCE.charMatcher('1'));
+        assertNotNull(andMatcher);
+        assertEquals(1, andMatcher.size());
     }
 
     @Test
@@ -117,18 +132,33 @@ public class StringMatcherFactoryTest {
 
     @Test
     public void test_stringMatcher() {
-        final StringMatcher stringMatcher = 
StringMatcherFactory.INSTANCE.stringMatcher("1");
+        StringMatcher stringMatcher = 
StringMatcherFactory.INSTANCE.stringMatcher("1");
         assertNotNull(stringMatcher);
         assertNotNull(stringMatcher.toString());
         assertEquals(1, stringMatcher.size());
+        //
+        stringMatcher = StringMatcherFactory.INSTANCE.stringMatcher();
+        assertNotNull(stringMatcher);
+        assertNotNull(stringMatcher.toString());
+        assertEquals(0, stringMatcher.size());
     }
 
     @Test
     public void test_stringMatcherChars() {
-        final StringMatcher stringMatcher = 
StringMatcherFactory.INSTANCE.stringMatcher('1', '2');
+        StringMatcher stringMatcher = 
StringMatcherFactory.INSTANCE.stringMatcher('1', '2');
         assertNotNull(stringMatcher);
         assertNotNull(stringMatcher.toString());
         assertEquals(2, stringMatcher.size());
+        //
+        stringMatcher = StringMatcherFactory.INSTANCE.stringMatcher('1');
+        assertNotNull(stringMatcher);
+        assertNotNull(stringMatcher.toString());
+        assertEquals(1, stringMatcher.size());
+        //
+        stringMatcher = StringMatcherFactory.INSTANCE.stringMatcher();
+        assertNotNull(stringMatcher);
+        assertNotNull(stringMatcher.toString());
+        assertEquals(0, stringMatcher.size());
     }
 
     @Test
@@ -147,4 +177,11 @@ public class StringMatcherFactoryTest {
         assertEquals(1, charMatcher.size());
     }
 
+    @Test
+    public void testDefaultMethods() {
+        final StringMatcherDefaults stringMatcher = new 
StringMatcherDefaults();
+        assertEquals(0, stringMatcher.size());
+        assertEquals(2, stringMatcher.isMatch("1", 0));
+    }
+
 }
diff --git 
a/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharArrayTest.java
 
b/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharArrayTest.java
index 6fb9e94..b23e5bf 100644
--- 
a/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharArrayTest.java
+++ 
b/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharArrayTest.java
@@ -54,9 +54,11 @@ public class StringMatcherOnCharArrayTest {
             StringMatcherFactory.INSTANCE.charMatcher('c'), 
StringMatcherFactory.INSTANCE.stringMatcher("de"));
         assertEquals(3, matcher1.size());
         checkAndMatcher_char(matcher1);
-        final StringMatcher matcher2 = 
StringMatcherFactory.INSTANCE.andMatcher(null, 
StringMatcherFactory.INSTANCE.charMatcher('c'), null,
-            StringMatcherFactory.INSTANCE.stringMatcher("de"), null);
-        assertEquals(3, matcher1.size());
+        //
+        final StringMatcher matcher2 = 
StringMatcherFactory.INSTANCE.andMatcher(null,
+            StringMatcherFactory.INSTANCE.charMatcher('c'), null, 
StringMatcherFactory.INSTANCE.stringMatcher("de"),
+            null);
+        assertEquals(3, matcher2.size());
         checkAndMatcher_char(matcher2);
     }
 
diff --git 
a/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharSequenceStringTest.java
 
b/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharSequenceStringTest.java
index d4fa2e9..fd0da14 100644
--- 
a/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharSequenceStringTest.java
+++ 
b/src/test/java/org/apache/commons/text/matcher/StringMatcherOnCharSequenceStringTest.java
@@ -54,10 +54,11 @@ public class StringMatcherOnCharSequenceStringTest {
             StringMatcherFactory.INSTANCE.charMatcher('c'), 
StringMatcherFactory.INSTANCE.stringMatcher("de"));
         assertEquals(3, matcher1.size());
         checkAndMatcher_char(matcher1);
+        //
         final StringMatcher matcher2 = 
StringMatcherFactory.INSTANCE.andMatcher(null,
             StringMatcherFactory.INSTANCE.charMatcher('c'), null, 
StringMatcherFactory.INSTANCE.stringMatcher("de"),
             null);
-        assertEquals(3, matcher1.size());
+        assertEquals(3, matcher2.size());
         checkAndMatcher_char(matcher2);
     }
 

Reply via email to