Skip to content

Commit 1587005

Browse files
committed
test: add unit tests for SeriesServiceImpl.addComment()
Fix #1409
1 parent eadae97 commit 1587005

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/test/groovy/ru/mystamps/web/feature/series/SeriesServiceImplTest.groovy

+39
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import static io.qala.datagen.RandomShortApi.bool
3232
import static io.qala.datagen.RandomShortApi.nullOr
3333
import static io.qala.datagen.RandomShortApi.positiveInteger
3434
import static io.qala.datagen.RandomShortApi.positiveLong
35+
import static io.qala.datagen.RandomShortApi.sample
3536

3637
@SuppressWarnings([
3738
'ClassJavadoc',
@@ -467,6 +468,44 @@ class SeriesServiceImplTest extends Specification {
467468
ex.message == 'oops'
468469
}
469470

471+
//
472+
// Tests for addComment()
473+
//
474+
475+
def 'addComment() should throw exception when series id is null'() {
476+
when:
477+
service.addComment(null, null)
478+
then:
479+
IllegalArgumentException ex = thrown()
480+
ex.message == 'Series id must be non null'
481+
}
482+
483+
def 'addComment() should throw exception when comment is null'() {
484+
when:
485+
service.addComment(Random.id(), null)
486+
then:
487+
IllegalArgumentException ex = thrown()
488+
ex.message == 'Comment must be non null'
489+
}
490+
491+
def 'addComment() should throw exception when comment is empty or blank'() {
492+
when:
493+
service.addComment(Random.id(), sample('', ' '))
494+
then:
495+
IllegalArgumentException ex = thrown()
496+
ex.message == 'Comment must be non empty'
497+
}
498+
499+
def 'addComment() should pass parameters to seried dao'() {
500+
given:
501+
Integer expectedSeriesId = Random.id()
502+
String expectedComment = 'this is important'
503+
when:
504+
service.addComment(expectedSeriesId, expectedComment)
505+
then:
506+
1 * seriesDao.addComment(expectedSeriesId, expectedComment)
507+
}
508+
470509
//
471510
// Tests for addImageToSeries()
472511
//

0 commit comments

Comments
 (0)