From 34a3096eb4570179414b92d238138596f3cc807e Mon Sep 17 00:00:00 2001 From: Edgar Asatryan <17509127+nstdio@users.noreply.github.com> Date: Sun, 25 Oct 2020 18:52:16 +0400 Subject: [PATCH] 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 7e2f4d164..3353f7a79 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 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++) {