Skip to content

Commit 1bc7c2f

Browse files
committed
CountryService.suggestCountryForUser(): add unit tests.
Fix #569 No functional changes.
1 parent 128920c commit 1bc7c2f

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,61 @@ class CountryServiceImplTest extends Specification {
419419
) >> null
420420
}
421421

422+
//
423+
// Tests for suggestCountryForUser()
424+
//
425+
426+
def 'suggestCountryForUser() should throw exception when user id is null'() {
427+
when:
428+
service.suggestCountryForUser(null)
429+
then:
430+
thrown IllegalArgumentException
431+
}
432+
433+
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
434+
def 'suggestCountryForUser() should return country of the last created series'() {
435+
given:
436+
Integer expectedUserId = 18
437+
String expectedSlug = 'brazil'
438+
when:
439+
String slug = service.suggestCountryForUser(expectedUserId)
440+
then:
441+
1 * countryDao.findCountryOfLastCreatedSeriesByUser(
442+
{ Integer userId ->
443+
assert expectedUserId == userId
444+
return true
445+
}
446+
) >> expectedSlug
447+
and:
448+
slug == expectedSlug
449+
}
450+
451+
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
452+
def 'suggestCountryForUser() should return popular country from collection'() {
453+
given:
454+
Integer expectedUserId = 19
455+
String expectedSlug = 'mexica'
456+
when:
457+
String slug = service.suggestCountryForUser(expectedUserId)
458+
then:
459+
1 * countryDao.findPopularCountryInCollection(
460+
{ Integer userId ->
461+
assert expectedUserId == userId
462+
return true
463+
}
464+
) >> expectedSlug
465+
and:
466+
slug == expectedSlug
467+
}
468+
469+
def 'suggestCountryForUser() should return null when cannot suggest'() {
470+
when:
471+
String slug = service.suggestCountryForUser(20)
472+
then:
473+
1 * countryDao.findCountryOfLastCreatedSeriesByUser(_ as Integer) >> null
474+
1 * countryDao.findPopularCountryInCollection(_ as Integer) >> null
475+
and:
476+
slug == null
477+
}
478+
422479
}

0 commit comments

Comments
 (0)