@@ -23,6 +23,7 @@ import static io.qala.datagen.RandomShortApi.nullOrBlank
23
23
import static io.qala.datagen.RandomValue.between
24
24
25
25
import spock.lang.Specification
26
+ import spock.lang.Unroll
26
27
27
28
import org.slf4j.helpers.NOPLogger
28
29
@@ -76,7 +77,8 @@ class SeriesImportServiceImplTest extends Specification {
76
77
when :
77
78
service. addRequest(null , Random . userId())
78
79
then :
79
- thrown IllegalArgumentException
80
+ IllegalArgumentException ex = thrown()
81
+ ex. message == ' DTO must be non null'
80
82
}
81
83
82
84
def ' addRequest() should throw exception if url is null' () {
@@ -85,14 +87,18 @@ class SeriesImportServiceImplTest extends Specification {
85
87
when :
86
88
service. addRequest(form, Random . userId())
87
89
then :
88
- thrown IllegalArgumentException
90
+ IllegalArgumentException ex = thrown()
91
+ ex. message == ' URL must be non null'
89
92
}
90
93
91
94
def ' addRequest() should throw exception if user id is null' () {
95
+ given :
96
+ form. setUrl(Random . url())
92
97
when :
93
98
service. addRequest(form, null )
94
99
then :
95
- thrown IllegalArgumentException
100
+ IllegalArgumentException ex = thrown()
101
+ ex. message == ' User id must be non null'
96
102
}
97
103
98
104
def ' addRequest() should throw exception if url is incorrect' () {
@@ -271,21 +277,24 @@ class SeriesImportServiceImplTest extends Specification {
271
277
when :
272
278
service. changeStatus(null , oldStatus, newStatus)
273
279
then :
274
- thrown IllegalArgumentException
280
+ IllegalArgumentException ex = thrown()
281
+ ex. message == ' Request id must be non null'
275
282
}
276
283
277
284
def ' changeStatus() should throw exception when old status is blank' () {
278
285
when :
279
286
service. changeStatus(Random . id(), nullOrBlank(), Random . importRequestStatus())
280
287
then :
281
- thrown IllegalArgumentException
288
+ IllegalArgumentException ex = thrown()
289
+ ex. message == ' Old status must be non-blank'
282
290
}
283
291
284
292
def ' changeStatus() should throw exception when new status is blank' () {
285
293
when :
286
294
service. changeStatus(Random . id(), Random . importRequestStatus(), nullOrBlank())
287
295
then :
288
- thrown IllegalArgumentException
296
+ IllegalArgumentException ex = thrown()
297
+ ex. message == ' New status must be non-blank'
289
298
}
290
299
291
300
def ' changeStatus() should throw exception when statuses are equal' () {
@@ -294,7 +303,8 @@ class SeriesImportServiceImplTest extends Specification {
294
303
when :
295
304
service. changeStatus(Random . id(), status, status)
296
305
then :
297
- thrown IllegalArgumentException
306
+ IllegalArgumentException ex = thrown()
307
+ ex. message == ' Statuses must be different'
298
308
}
299
309
300
310
@SuppressWarnings (' UnnecessaryReturnKeyword' )
@@ -327,7 +337,8 @@ class SeriesImportServiceImplTest extends Specification {
327
337
when :
328
338
service. findById(null )
329
339
then :
330
- thrown IllegalArgumentException
340
+ IllegalArgumentException ex = thrown()
341
+ ex. message == ' Request id must be non null'
331
342
}
332
343
333
344
def ' findById() should invoke dao, pass argument and return result from dao' () {
@@ -353,14 +364,21 @@ class SeriesImportServiceImplTest extends Specification {
353
364
when :
354
365
service. saveDownloadedContent(null , content)
355
366
then :
356
- thrown IllegalArgumentException
367
+ IllegalArgumentException ex = thrown()
368
+ ex. message == ' Request id must be non null'
357
369
}
358
370
359
- def ' saveDownloadedContent() should throw exception when content is blank' () {
371
+ @Unroll
372
+ def " saveDownloadedContent() should throw exception when content is '#content'" (String content) {
360
373
when :
361
- service. saveDownloadedContent(Random . id(), nullOrBlank() )
374
+ service. saveDownloadedContent(Random . id(), content )
362
375
then :
363
- thrown IllegalArgumentException
376
+ IllegalArgumentException ex = thrown()
377
+ ex. message == ' Content must be non-blank'
378
+ where :
379
+ content | _
380
+ ' ' | _
381
+ ' ' | _
364
382
}
365
383
366
384
@SuppressWarnings (' UnnecessaryReturnKeyword' )
@@ -411,7 +429,8 @@ class SeriesImportServiceImplTest extends Specification {
411
429
when :
412
430
service. getDownloadedContent(null )
413
431
then :
414
- thrown IllegalArgumentException
432
+ IllegalArgumentException ex = thrown()
433
+ ex. message == ' Request id must be non null'
415
434
}
416
435
417
436
def ' getDownloadedContent() should invoke dao, pass argument and return result from dao' () {
@@ -437,14 +456,16 @@ class SeriesImportServiceImplTest extends Specification {
437
456
when :
438
457
service. saveParsedData(null , TestObjects . createEmptySeriesExtractedInfo(), Random . url())
439
458
then :
440
- thrown IllegalArgumentException
459
+ IllegalArgumentException ex = thrown()
460
+ ex. message == ' Request id must be non null'
441
461
}
442
462
443
463
def ' saveParsedData() should throw exception when series info is null' () {
444
464
when :
445
465
service. saveParsedData(Random . id(), null , Random . url())
446
466
then :
447
- thrown IllegalArgumentException
467
+ IllegalArgumentException ex = thrown()
468
+ ex. message == ' Series info must be non null'
448
469
}
449
470
450
471
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -566,7 +587,8 @@ class SeriesImportServiceImplTest extends Specification {
566
587
when :
567
588
service. getParsedData(null , Random . lang())
568
589
then :
569
- thrown IllegalArgumentException
590
+ IllegalArgumentException ex = thrown()
591
+ ex. message == ' Request id must be non null'
570
592
}
571
593
572
594
def ' getParsedData() should invoke dao, pass argument and return result from dao' () {
@@ -591,7 +613,8 @@ class SeriesImportServiceImplTest extends Specification {
591
613
when :
592
614
service. findRequestInfo(null )
593
615
then :
594
- thrown IllegalArgumentException
616
+ IllegalArgumentException ex = thrown()
617
+ ex. message == ' Series id must be non null'
595
618
}
596
619
597
620
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
0 commit comments