You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/10/25 14:52:23 UTC

[commons-lang] branch master updated: More coverage for CharSequenceUtils. (#631)

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-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 34a3096  More coverage for CharSequenceUtils. (#631)
34a3096 is described below

commit 34a3096eb4570179414b92d238138596f3cc807e
Author: Edgar Asatryan <17...@users.noreply.github.com>
AuthorDate: Sun Oct 25 18:52:16 2020 +0400

    More coverage for CharSequenceUtils. (#631)
---
 .../commons/lang3/CharSequenceUtilsTest.java       | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java b/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java
index 7e2f4d1..3353f7a 100644
--- a/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java
@@ -23,13 +23,18 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 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 static org.junit.jupiter.params.provider.Arguments.arguments;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
 import java.util.Random;
 import java.util.stream.IntStream;
+import java.util.stream.Stream;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 /**
  * Tests CharSequenceUtils
@@ -261,6 +266,25 @@ public class CharSequenceUtilsTest {
         }
     }
 
+    @ParameterizedTest
+    @MethodSource("lastIndexWithStandardCharSequence")
+    public void testLastIndexOfWithDifferentCharSequences(CharSequence cs, CharSequence search, int start,
+                                                          int expected) {
+        assertEquals(expected, CharSequenceUtils.lastIndexOf(cs, search, start));
+    }
+
+    static Stream<Arguments> lastIndexWithStandardCharSequence() {
+        return Stream.of(
+            arguments("abc", "b", 2, 1),
+            arguments(new StringBuilder("abc"), "b", 2, 1),
+            arguments(new StringBuffer("abc"), "b", 2, 1),
+            arguments("abc", new StringBuilder("b"), 2, 1),
+            arguments(new StringBuilder("abc"), new StringBuilder("b"), 2, 1),
+            arguments(new StringBuffer("abc"), new StringBuffer("b"), 2, 1),
+            arguments(new StringBuilder("abc"), new StringBuffer("b"), 2, 1)
+        );
+    }
+
     private void testNewLastIndexOfSingle(final CharSequence a, final CharSequence b) {
         final int maxa = Math.max(a.length(), b.length());
         for (int i = -maxa - 10; i <= maxa + 10; i++) {