Skip to content

Commit

Permalink
(v2.5.0) Add mixedCase() for upper/lower case randomization
Browse files Browse the repository at this point in the history
Strings like `blah` can be turned into `bLAh`.
  • Loading branch information
ctapobep committed Aug 10, 2019
1 parent c648ee2 commit 2e790d4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion datagen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qala-datagen-parent</artifactId>
<groupId>io.qala.datagen</groupId>
<version>2.4.0</version>
<version>2.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
14 changes: 14 additions & 0 deletions datagen/src/main/java/io/qala/datagen/RandomShortApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
13 changes: 11 additions & 2 deletions datagen/src/test/java/io/qala/datagen/RandomShortApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qala-datagen-parent</artifactId>
<groupId>io.qala.datagen</groupId>
<version>2.4.0</version>
<version>2.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion java8types/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qala-datagen-parent</artifactId>
<groupId>io.qala.datagen</groupId>
<version>2.4.0</version>
<version>2.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qala-datagen-parent</artifactId>
<groupId>io.qala.datagen</groupId>
<version>2.4.0</version>
<version>2.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.qala.datagen</groupId>
<artifactId>qala-datagen-parent</artifactId>
<packaging>pom</packaging>
<version>2.4.0</version>
<version>2.5.0</version>

<licenses>
<license>
Expand Down

0 comments on commit 2e790d4

Please sign in to comment.