diff --git a/pom.xml b/pom.xml
index 1d0b763..76dd961 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
4.0.0
com.ocadotechnology.gembus
test-arranger
- 1.4-SNAPSHOT
+ 1.4
jar
test-arranger
A tool for arranging test data with pseudo-random values.
diff --git a/src/main/java/com/ocadotechnology/gembus/test/Arranger.java b/src/main/java/com/ocadotechnology/gembus/test/Arranger.java
index 4b3f45b..7ba4a06 100644
--- a/src/main/java/com/ocadotechnology/gembus/test/Arranger.java
+++ b/src/main/java/com/ocadotechnology/gembus/test/Arranger.java
@@ -16,6 +16,9 @@
package com.ocadotechnology.gembus.test;
import org.jeasy.random.randomizers.EmailRandomizer;
+import org.jeasy.random.randomizers.FirstNameRandomizer;
+import org.jeasy.random.randomizers.LastNameRandomizer;
+import org.jeasy.random.randomizers.RegularExpressionRandomizer;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -33,6 +36,8 @@ public class Arranger {
private static EnhancedRandom simplifiedRandom = ArrangersConfigurer.instance().simplifiedRandom();
private static final EmailRandomizer emailRandomizer = new EmailRandomizer();
private static final MarkovStringRandomizer stringRandomizer = new MarkovStringRandomizer(ArrangersConfigurer.STRING_MIN_LENGTH, ArrangersConfigurer.STRING_MAX_LENGTH);
+ private static final FirstNameRandomizer firstNameRandomizer = new FirstNameRandomizer();
+ private static final LastNameRandomizer lastNameRandomizer = new LastNameRandomizer();
/**
* @see org.jeasy.random.EasyRandom#nextObject
@@ -227,6 +232,18 @@ public static BigDecimal somePriceLikeBigDecimal(BigDecimal min, BigDecimal max)
return new BigDecimal(valueInCents).divide(centsRatio).add(min);
}
+ public static String someFirstName() {
+ return firstNameRandomizer.getRandomValue();
+ }
+
+ public static String someLastName() {
+ return lastNameRandomizer.getRandomValue();
+ }
+
+ public static String someStringLike(String regex) {
+ return new RegularExpressionRandomizer(regex).getRandomValue();
+ }
+
static class CannotSatisfyPredicateException extends RuntimeException {
public CannotSatisfyPredicateException(String type) {
super("Cannot satisfy provided predicate when generating data of type " + type);
diff --git a/src/main/kotlin/com/ocadotechnology/gembus/test/testUtils.kt b/src/main/kotlin/com/ocadotechnology/gembus/test/testUtils.kt
index a9baf03..35f92ee 100644
--- a/src/main/kotlin/com/ocadotechnology/gembus/test/testUtils.kt
+++ b/src/main/kotlin/com/ocadotechnology/gembus/test/testUtils.kt
@@ -27,16 +27,16 @@ inline fun some(adjustment: T.() -> Unit): T {
}
inline fun some(vararg excludedFields: String) =
- Arranger.some(T::class.java, *excludedFields)!!
+ Arranger.some(T::class.java, *excludedFields)!!
inline fun someSimplified(vararg excludedFields: String): T =
- Arranger.someSimplified(T::class.java, *excludedFields)!!
+ Arranger.someSimplified(T::class.java, *excludedFields)!!
inline fun someObjects(numberOfObjects: Int, vararg excludedFields: String) =
- Arranger.someObjects(T::class.java, numberOfObjects, *excludedFields).iterator().asSequence()
+ Arranger.someObjects(T::class.java, numberOfObjects, *excludedFields).iterator().asSequence()
inline fun someMatching(crossinline predicate: (T) -> Boolean, vararg excludedFields: String) =
- Arranger.someMatching(T::class.java, Predicate { predicate.invoke(it) }, *excludedFields)!!
+ Arranger.someMatching(T::class.java, Predicate { predicate.invoke(it) }, *excludedFields)!!
fun someInt(): Int = Arranger.someInteger()
fun someInt(minValue: Int, maxValue: Int): Int = Arranger.someInteger(minValue, maxValue)
@@ -57,12 +57,15 @@ fun somePositiveLong(boundInclusive: Long): Long = Arranger.somePositiveLong(bou
fun someEmail(): String = Arranger.someEmail()
fun someMatchingOrNull(array: Array, predicate: (T) -> Boolean): T? =
- Arranger.someMatching(array, predicate)
+ Arranger.someMatching(array, predicate)
fun someMatching(array: Array, predicate: (T) -> Boolean) =
- someMatchingOrNull(array, predicate) ?: throw RuntimeException("No match found.")
+ someMatchingOrNull(array, predicate) ?: throw RuntimeException("No match found.")
fun someGivenOrLater(given: LocalDate): LocalDate = Arranger.someGivenOrLater(given)
fun someGivenOrEarlier(given: LocalDate): LocalDate = Arranger.someGivenOrEarlier(given)
fun someInstant(): Instant = Arranger.someInstant()
fun someFrom(source: Collection): T = Arranger.someFrom(source)
+fun someFirstName(): String = Arranger.someFirstName()
+fun someLastName(): String = Arranger.someLastName()
+fun someStringLike(regex: String): String = Arranger.someStringLike(regex)
\ No newline at end of file
diff --git a/src/test/java/com/ocadotechnology/gembus/test/ArrangerTest.java b/src/test/java/com/ocadotechnology/gembus/test/ArrangerTest.java
index 57b7563..05acb4d 100644
--- a/src/test/java/com/ocadotechnology/gembus/test/ArrangerTest.java
+++ b/src/test/java/com/ocadotechnology/gembus/test/ArrangerTest.java
@@ -367,6 +367,27 @@ public void shouldGenerateIntFromRangeOverNegativeNumbers() {
.isGreaterThanOrEqualTo(min);
}
}
+
+ @Test
+ public void should_generateFirstName() {
+ //when
+ String actual = Arranger.someFirstName();
+
+ //then
+ assertThat(actual.length()).isGreaterThan(1);
+ assertThat(actual.charAt(0)).isUpperCase();
+ assertThat(actual.substring(1)).isEqualTo(actual.substring(1).toLowerCase(Locale.ROOT));
+ }
+
+ @Test
+ public void should_generateLastName() {
+ //when
+ String actual = Arranger.someLastName();
+
+ //then
+ assertThat(actual.length()).isGreaterThan(1);
+ assertThat(actual.charAt(0)).isUpperCase();
+ }
}
class SomeClass {