@@ -58,7 +58,8 @@ class ImageServiceImplTest extends Specification {
58
58
when :
59
59
service. save(null )
60
60
then :
61
- thrown IllegalArgumentException
61
+ IllegalArgumentException ex = thrown()
62
+ ex. message == ' File must be non null'
62
63
}
63
64
64
65
def " save() should throw exception if file has zero size" () {
@@ -67,7 +68,8 @@ class ImageServiceImplTest extends Specification {
67
68
then :
68
69
multipartFile. size >> 0L
69
70
and :
70
- thrown IllegalArgumentException
71
+ IllegalArgumentException ex = thrown()
72
+ ex. message == ' Image size must be greater than zero'
71
73
}
72
74
73
75
def " save() should throw exception if content type is null" () {
@@ -76,7 +78,8 @@ class ImageServiceImplTest extends Specification {
76
78
then :
77
79
multipartFile. contentType >> null
78
80
and :
79
- thrown IllegalArgumentException
81
+ IllegalArgumentException ex = thrown()
82
+ ex. message == ' File type must be non null'
80
83
}
81
84
82
85
def " save() should throw exception for unsupported content type" () {
@@ -85,7 +88,8 @@ class ImageServiceImplTest extends Specification {
85
88
then :
86
89
multipartFile. contentType >> ' image/tiff'
87
90
and :
88
- thrown IllegalStateException
91
+ IllegalStateException ex = thrown()
92
+ ex. message == " File type must be PNG or JPEG image, but 'image/tiff' (tiff) were passed"
89
93
}
90
94
91
95
@Unroll
@@ -168,7 +172,8 @@ class ImageServiceImplTest extends Specification {
168
172
and :
169
173
0 * imagePersistenceStrategy. save(_ as MultipartFile , _ as ImageInfoDto )
170
174
and :
171
- thrown ImagePersistenceException
175
+ ImagePersistenceException ex = thrown()
176
+ ex. message == " Can't save image"
172
177
}
173
178
174
179
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -207,15 +212,23 @@ class ImageServiceImplTest extends Specification {
207
212
// Tests for get()
208
213
//
209
214
215
+ def ' get() should throw exception if image id is null' () {
216
+ when :
217
+ service. get(null )
218
+ then :
219
+ IllegalArgumentException ex = thrown()
220
+ ex. message == ' Image id must be non null'
221
+ }
222
+
210
223
@Unroll
211
224
def " get() should throw exception if image id is #imageId" (Integer imageId) {
212
225
when :
213
226
service. get(imageId)
214
227
then :
215
- thrown IllegalArgumentException
228
+ IllegalArgumentException ex = thrown()
229
+ ex. message == ' Image id must be greater than zero'
216
230
where :
217
231
imageId | _
218
- null | _
219
232
-1 | _
220
233
0 | _
221
234
}
@@ -277,15 +290,23 @@ class ImageServiceImplTest extends Specification {
277
290
// Tests for getOrCreatePreview()
278
291
//
279
292
293
+ def ' getOrCreatePreview() should throw exception if image id is null' () {
294
+ when :
295
+ service. getOrCreatePreview(null )
296
+ then :
297
+ IllegalArgumentException ex = thrown()
298
+ ex. message == ' Image id must be non null'
299
+ }
300
+
280
301
@Unroll
281
302
def " getOrCreatePreview() should throw exception if image id is #imageId" (Integer imageId) {
282
303
when :
283
304
service. getOrCreatePreview(imageId)
284
305
then :
285
- thrown IllegalArgumentException
306
+ IllegalArgumentException ex = thrown()
307
+ ex. message == ' Image id must be greater than zero'
286
308
where :
287
309
imageId | _
288
- null | _
289
310
-1 | _
290
311
0 | _
291
312
}
@@ -317,14 +338,16 @@ class ImageServiceImplTest extends Specification {
317
338
when :
318
339
service. addToSeries(null , 1 )
319
340
then :
320
- thrown IllegalArgumentException
341
+ IllegalArgumentException ex = thrown()
342
+ ex. message == ' Series id must be non null'
321
343
}
322
344
323
345
def " addToSeries() should throw exception when image id is null" () {
324
346
when :
325
347
service. addToSeries(1 , null )
326
348
then :
327
- thrown IllegalArgumentException
349
+ IllegalArgumentException ex = thrown()
350
+ ex. message == ' Image id must be non null'
328
351
}
329
352
330
353
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -352,7 +375,8 @@ class ImageServiceImplTest extends Specification {
352
375
when :
353
376
service. findBySeriesId(null )
354
377
then :
355
- thrown IllegalArgumentException
378
+ IllegalArgumentException ex = thrown()
379
+ ex. message == ' Series id must be non null'
356
380
}
357
381
358
382
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -380,7 +404,8 @@ class ImageServiceImplTest extends Specification {
380
404
when :
381
405
service. removeIfPossible(null )
382
406
then :
383
- thrown IllegalArgumentException
407
+ IllegalArgumentException ex = thrown()
408
+ ex. message == ' Image info must be non null'
384
409
}
385
410
386
411
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
0 commit comments