-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
150 additions
and
75 deletions.
There are no files selected for viewing
44 changes: 0 additions & 44 deletions
44
modules/random/src/main/java/org/stubit/random/RandomChar.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 81 additions & 11 deletions
92
modules/random/src/test/java/org/stubit/random/RandomStringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,95 @@ | ||
package org.stubit.random; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.stubit.random.RandomChar.aLatinLetter; | ||
import static org.stubit.random.RandomChar.anArabicDigit; | ||
import static org.stubit.random.RandomString.aStringStartingWith; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.stubit.random.RandomInt.anIntBetween; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class RandomStringTest { | ||
|
||
@Test | ||
void followedBy_mixed() { | ||
void aLetterFrom() { | ||
assertThat(RandomString.aLetterFrom(Alphabet.GERMAN)).matches("[a-zA-ZöäüßÄÖÜẞ]"); | ||
} | ||
|
||
@Test | ||
void lettersFrom() { | ||
int number = anIntBetween(1, 10); | ||
assertThat(RandomString.lettersFrom(number, Alphabet.GERMAN)) | ||
.matches("[a-zA-ZöäüßÄÖÜẞ]+") | ||
.hasSize(number); | ||
} | ||
|
||
@Test | ||
void lettersFrom_zero() { | ||
assertThat(RandomString.lettersFrom(0, Alphabet.FRENCH)).isEmpty(); | ||
} | ||
|
||
@Test | ||
void lettersFrom_negative() { | ||
assertThatThrownBy(() -> RandomString.lettersFrom(-1, Alphabet.FRENCH)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void aLatinLetter() { | ||
assertThat(RandomString.aLatinLetter()).matches("[a-zA-Z]"); | ||
} | ||
|
||
@Test | ||
void latinLetters() { | ||
int number = anIntBetween(1, 10); | ||
assertThat(RandomString.latinLetters(number)).matches("[a-zA-Z]+").hasSize(number); | ||
} | ||
|
||
@Test | ||
void latinLetters_zero() { | ||
assertThat(RandomString.latinLetters(0)).isEmpty(); | ||
} | ||
|
||
@Test | ||
void latinLetters_negative() { | ||
assertThatThrownBy(() -> RandomString.latinLetters(-1)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void anArabicDigit() { | ||
assertThat(RandomString.anArabicDigit()).matches("[0-9]"); | ||
} | ||
|
||
@Test | ||
void arabicDigits() { | ||
int number = anIntBetween(1, 10); | ||
assertThat(RandomString.arabicDigits(number)).matches("[0-9]+").hasSize(number); | ||
} | ||
|
||
@Test | ||
void arabicDigits_zero() { | ||
assertThat(RandomString.arabicDigits(0)).isEmpty(); | ||
} | ||
|
||
@Test | ||
void arabicDigits_negative() { | ||
assertThatThrownBy(() -> RandomString.arabicDigits(-1)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void aStringStartingWith() { | ||
var string = RandomString.aStringStartingWith(RandomString.aLatinLetter()).build(); | ||
|
||
assertThat(string).matches("[a-zA-Z]"); | ||
} | ||
|
||
@Test | ||
void followedBy() { | ||
var string = | ||
aStringStartingWith(aLatinLetter()) | ||
.followedBy('-') | ||
.followedBy(anArabicDigit()) | ||
.followedBy("üäößø") | ||
RandomString.aStringStartingWith(RandomString.aLatinLetter()) | ||
.followedBy(RandomString.anArabicDigit()) | ||
.build(); | ||
|
||
System.out.println(string); | ||
|
||
assertThat(string).matches("[a-zA-Z]-[0-9]üäößø"); | ||
assertThat(string).matches("[a-zA-Z][0-9]"); | ||
} | ||
} |