Skip to content

Commit 2ccba86

Browse files
committed
Random.{category,country}Name(): avoid returning name that starts/ends with a space or hypen.
Reduce unit tests flakes.
1 parent 5eb1b71 commit 2ccba86

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/test/java/ru/mystamps/web/tests/Random.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.List;
2424
import java.util.Set;
2525

26+
import org.apache.commons.lang3.StringUtils;
27+
2628
import io.qala.datagen.RandomShortApi;
2729

2830
import ru.mystamps.web.Db.SeriesImportRequestStatus;
@@ -79,21 +81,35 @@ public static String name() {
7981
}
8082

8183
public static String categoryName() {
82-
return between(
84+
String name = between(
8385
ValidationRules.CATEGORY_NAME_MIN_LENGTH,
8486
ValidationRules.CATEGORY_NAME_MAX_LENGTH
8587
)
8688
.with(oneOf(" -"))
8789
.english();
90+
91+
if (StringUtils.startsWithAny(name, " ", "-")
92+
|| StringUtils.endsWithAny(name, " ", "-")) {
93+
return countryName();
94+
}
95+
96+
return name;
8897
}
8998

9099
public static String countryName() {
91-
return between(
100+
String name = between(
92101
ValidationRules.COUNTRY_NAME_MIN_LENGTH,
93102
ValidationRules.COUNTRY_NAME_MAX_LENGTH
94103
)
95104
.with(oneOf(" -"))
96105
.english();
106+
107+
if (StringUtils.startsWithAny(name, " ", "-")
108+
|| StringUtils.endsWithAny(name, " ", "-")) {
109+
return countryName();
110+
}
111+
112+
return name;
97113
}
98114

99115
public static String participantName() {

0 commit comments

Comments
 (0)