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 2023/06/26 20:24:48 UTC

[commons-text] branch master updated: Test some edge cases

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 6c2b7c08 Test some edge cases
6c2b7c08 is described below

commit 6c2b7c08d0fee3176ef6e90710748849ae489961
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jun 26 16:24:44 2023 -0400

    Test some edge cases
---
 .../commons/text/RandomStringGeneratorTest.java    | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
index ee5d580a..927fe853 100644
--- a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
+++ b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
 import static org.assertj.core.api.Assertions.assertThatNullPointerException;
 import static org.assertj.core.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.junit.jupiter.api.Test;
@@ -213,6 +214,33 @@ public class RandomStringGeneratorTest {
         }
     }
 
+    @Test
+    public void testSelectFromCharVarargs2() {
+        final String str = "abcde";
+        // @formatter:off
+        final RandomStringGenerator generator = new RandomStringGenerator.Builder()
+                .selectFrom()
+                .selectFrom('a', 'b')
+                .selectFrom('a', 'b', 'c')
+                .selectFrom('a', 'b', 'c', 'd')
+                .selectFrom('a', 'b', 'c', 'd', 'e') // only this last call matters
+                .build();
+        // @formatter:on
+        final String randomText = generator.generate(10);
+        for (final char c : randomText.toCharArray()) {
+            assertThat(str.indexOf(c) != -1).isTrue();
+        }
+    }
+
+    @Test
+    public void testSelectFromCharVarargSize1() {
+        final RandomStringGenerator generator = new RandomStringGenerator.Builder().selectFrom('a').build();
+        final String randomText = generator.generate(5);
+        for (final char c : randomText.toCharArray()) {
+            assertEquals('a', c);
+        }
+    }
+
     @Test
     public void testSelectFromEmptyCharVarargs() {
         final RandomStringGenerator generator = new RandomStringGenerator.Builder().selectFrom().build();