diff --git a/README.md b/README.md
index bcd9d57..d2843fd 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,7 @@ import static io.qala.datagen.RandomShortApi.*;
| `length(4).with(spacesRight(2)).english()` | | `"hF "`
| `length(10).with(prefix("BLAH")).numeric()` | | `"BLAH453677"`
| `between(1, 10).alphanumerics(4)` | | `["cvA", "mTMDj0", "N", ""]`
+| | `mixedCase("blah")` | `"bLaH"`
## Nulls & Blanks
diff --git a/datagen/pom.xml b/datagen/pom.xml
index 2fb094b..4a862d0 100644
--- a/datagen/pom.xml
+++ b/datagen/pom.xml
@@ -5,7 +5,7 @@
qala-datagen-parent
io.qala.datagen
- 2.4.0
+ 2.5.0
4.0.0
diff --git a/datagen/src/main/java/io/qala/datagen/RandomShortApi.java b/datagen/src/main/java/io/qala/datagen/RandomShortApi.java
index 9c46ed0..6e70cc7 100644
--- a/datagen/src/main/java/io/qala/datagen/RandomShortApi.java
+++ b/datagen/src/main/java/io/qala/datagen/RandomShortApi.java
@@ -175,6 +175,20 @@ public static String specialSymbols(int exactLength) {
public static String specialSymbols(int min, int max) {
return between(min, max).specialSymbols();
}
+ /**
+ * Returns a string with upper/lower case changed in random places, e.g. {@code Blah -> bLaH}
+ *
+ * @param original string to change the case of its letters, can't be null
+ * @return a string with upper/lower case letters in random places
+ */
+ public static String mixedCase(String original) {
+ char[] result = original.toCharArray();
+ for (int i = 0; i < result.length; i++) {
+ char c = result[i];
+ result[i] = bool() ? Character.toUpperCase(c) : Character.toLowerCase(c);
+ }
+ return new String(result);
+ }
/**
* Returns an array of random booleans (true/false).
diff --git a/datagen/src/test/java/io/qala/datagen/RandomShortApiTest.java b/datagen/src/test/java/io/qala/datagen/RandomShortApiTest.java
index 3fd5ee0..47a1664 100644
--- a/datagen/src/test/java/io/qala/datagen/RandomShortApiTest.java
+++ b/datagen/src/test/java/io/qala/datagen/RandomShortApiTest.java
@@ -13,8 +13,7 @@
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNot.not;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Functional Randomizer")
class RandomShortApiTest {
@@ -46,6 +45,16 @@ class RandomShortApiTest {
assertFalse(sampleMultiple(asList(integer(), integer())).isEmpty());
}
+ @Test void mixedCaseReturnsSameStringWithDifferentCases() {
+ String original = alphanumeric(200);
+ String mixed = mixedCase(original);
+ assertNotEquals(original, mixed);
+ assertEquals(original.toLowerCase(), mixed.toLowerCase());
+ }
+ @Test void emptyStringInMixedCaseIsEmptyString() {
+ assertEquals("", mixedCase(blankOr("")));
+ }
+
private void assertOnlyOneIsNull(Object o1, Object o2) {
if (o1 == null) assertNotNull(o2);
if (o2 == null) assertNotNull(o1);
diff --git a/examples/pom.xml b/examples/pom.xml
index 7f5ddc9..26dce0c 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -5,7 +5,7 @@
qala-datagen-parent
io.qala.datagen
- 2.4.0
+ 2.5.0
4.0.0
diff --git a/java8types/pom.xml b/java8types/pom.xml
index c51dfe8..f82fc57 100644
--- a/java8types/pom.xml
+++ b/java8types/pom.xml
@@ -5,7 +5,7 @@
qala-datagen-parent
io.qala.datagen
- 2.4.0
+ 2.5.0
4.0.0
diff --git a/junit5/pom.xml b/junit5/pom.xml
index 6abdee5..86ae7c9 100644
--- a/junit5/pom.xml
+++ b/junit5/pom.xml
@@ -5,7 +5,7 @@
qala-datagen-parent
io.qala.datagen
- 2.4.0
+ 2.5.0
4.0.0
diff --git a/pom.xml b/pom.xml
index 45b751e..efa2242 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
io.qala.datagen
qala-datagen-parent
pom
- 2.4.0
+ 2.5.0