Skip to content

Commit 5c65fb4

Browse files
committed
refactor(CountryServiceImplTest): use random values in tests for suggestCountryForUser() method.
Addressed to #300
1 parent 5637129 commit 5c65fb4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/test/groovy/ru/mystamps/web/feature/country/CountryServiceImplTest.groovy

+7-7
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ class CountryServiceImplTest extends Specification {
449449

450450
def 'suggestCountryForUser() should return country of the last created series'() {
451451
given:
452-
Integer expectedUserId = 18
453-
String expectedSlug = 'brazil'
452+
Integer expectedUserId = Random.userId()
453+
String expectedSlug = Random.countrySlug()
454454
when:
455455
String slug = service.suggestCountryForUser(expectedUserId)
456456
then:
@@ -461,8 +461,8 @@ class CountryServiceImplTest extends Specification {
461461

462462
def 'suggestCountryForUser() should return popular country from collection'() {
463463
given:
464-
Integer expectedUserId = 19
465-
String expectedSlug = 'mexica'
464+
Integer expectedUserId = Random.userId()
465+
String expectedSlug = Random.countrySlug()
466466
when:
467467
String slug = service.suggestCountryForUser(expectedUserId)
468468
then:
@@ -473,8 +473,8 @@ class CountryServiceImplTest extends Specification {
473473

474474
def 'suggestCountryForUser() should return a recently created country'() {
475475
given:
476-
Integer expectedUserId = 21
477-
String expectedSlug = 'spain'
476+
Integer expectedUserId = Random.userId()
477+
String expectedSlug = Random.countrySlug()
478478
when:
479479
String slug = service.suggestCountryForUser(expectedUserId)
480480
then:
@@ -485,7 +485,7 @@ class CountryServiceImplTest extends Specification {
485485

486486
def 'suggestCountryForUser() should return null when cannot suggest'() {
487487
when:
488-
String slug = service.suggestCountryForUser(20)
488+
String slug = service.suggestCountryForUser(Random.userId())
489489
then:
490490
1 * countryDao.findCountryOfLastCreatedSeriesByUser(_ as Integer) >> null
491491
1 * countryDao.findPopularCountryInCollection(_ as Integer) >> null

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

+4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ public static String countryName() {
167167
return name;
168168
}
169169

170+
public static String countrySlug() {
171+
return SlugUtils.slugify(countryName());
172+
}
173+
170174
public static String participantName() {
171175
return between(
172176
ValidationRules.PARTICIPANT_NAME_MIN_LENGTH,

0 commit comments

Comments
 (0)