Skip to content

Commit 5e26ab5

Browse files
committed
SeriesServiceImpl.addImageToSeries(): add unit tests.
Fix #100
1 parent 75861f0 commit 5e26ab5

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

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

+54-1
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,64 @@ class SeriesServiceImplTest extends Specification {
591591
// Tests for addImageToSeries()
592592
//
593593

594+
def "addImageToSeries() should throw exception when dto is null"() {
595+
when:
596+
service.addImageToSeries(null, 111, 222)
597+
then:
598+
thrown IllegalArgumentException
599+
}
600+
601+
def "addImageToSeries() should throw exception when series id is null"() {
602+
when:
603+
service.addImageToSeries(imageForm, null, 222)
604+
then:
605+
thrown IllegalArgumentException
606+
}
607+
608+
def "addImageToSeries() should throw exception when user id is null"() {
609+
when:
610+
service.addImageToSeries(imageForm, 111, null)
611+
then:
612+
thrown IllegalArgumentException
613+
}
614+
594615
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
595-
def "addImageToSeries() should call dao and pass series id, current date and user id to it"() {
616+
def "addImageToSeries() should save image"() {
617+
given:
618+
imageForm.setImage(multipartFile)
619+
when:
620+
service.addImageToSeries(imageForm, 111, 222)
621+
then:
622+
1 * imageService.save({ MultipartFile passedFile ->
623+
assert passedFile == multipartFile
624+
return true
625+
}) >> ANY_IMAGE_ID
626+
}
627+
628+
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
629+
def "addImageToSeries() should add image to series"() {
596630
given:
597631
Integer expectedSeriesId = 123
632+
Integer expectedUserId = 321
633+
Integer expectedImageId = 456
634+
when:
635+
service.addImageToSeries(imageForm, expectedSeriesId, expectedUserId)
636+
then:
637+
imageService.save(_) >> expectedImageId
598638
and:
639+
1 * imageService.addToSeries({ Integer seriesId ->
640+
assert seriesId == expectedSeriesId
641+
return true
642+
}, { Integer imageId ->
643+
assert imageId == expectedImageId
644+
return true
645+
})
646+
}
647+
648+
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
649+
def "addImageToSeries() should mark series as modified"() {
650+
given:
651+
Integer expectedSeriesId = 123
599652
Integer expectedUserId = 321
600653
when:
601654
service.addImageToSeries(imageForm, expectedSeriesId, expectedUserId)

0 commit comments

Comments
 (0)