@@ -56,7 +56,8 @@ class CategoryServiceImplTest extends Specification {
56
56
when :
57
57
service. add(null , Random . userId())
58
58
then :
59
- thrown IllegalArgumentException
59
+ IllegalArgumentException ex = thrown()
60
+ ex. message == ' DTO must be non null'
60
61
}
61
62
62
63
def " add() should throw exception when English category name is null" () {
@@ -65,14 +66,16 @@ class CategoryServiceImplTest extends Specification {
65
66
when :
66
67
service. add(form, Random . userId())
67
68
then :
68
- thrown IllegalArgumentException
69
+ IllegalArgumentException ex = thrown()
70
+ ex. message == ' Category name in English must be non null'
69
71
}
70
72
71
73
def " add() should throw exception when user is null" () {
72
74
when :
73
75
service. add(form, null )
74
76
then :
75
- thrown IllegalArgumentException
77
+ IllegalArgumentException ex = thrown()
78
+ ex. message == ' User id must be non null'
76
79
}
77
80
78
81
def " add() should call dao" () {
@@ -92,11 +95,12 @@ class CategoryServiceImplTest extends Specification {
92
95
93
96
def " add() should throw exception when name can't be converted to slug" () {
94
97
given :
95
- form. setName(null )
98
+ form. setName(' - ' )
96
99
when :
97
100
service. add(form, Random . userId())
98
101
then :
99
- thrown IllegalArgumentException
102
+ IllegalArgumentException ex = thrown()
103
+ ex. message == " Slug for string '-' must be non empty"
100
104
}
101
105
102
106
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -170,7 +174,8 @@ class CategoryServiceImplTest extends Specification {
170
174
when :
171
175
service. findIdsWhenNameStartsWith(nullOrBlank())
172
176
then :
173
- thrown IllegalArgumentException
177
+ IllegalArgumentException ex = thrown()
178
+ ex. message == ' Name must be non-blank'
174
179
}
175
180
176
181
def ' findIdsWhenNameStartsWith() should throw exception when name contains percent or underscore character' () {
@@ -179,7 +184,8 @@ class CategoryServiceImplTest extends Specification {
179
184
when :
180
185
service. findIdsWhenNameStartsWith(invalidName)
181
186
then :
182
- thrown IllegalArgumentException
187
+ IllegalArgumentException ex = thrown()
188
+ ex. message == " Name must not contain '%' or '_' chars"
183
189
}
184
190
185
191
def ' findIdsWhenNameStartsWith() should invoke dao, pass argument and return result from dao' () {
@@ -247,17 +253,25 @@ class CategoryServiceImplTest extends Specification {
247
253
// Tests for findOneAsLinkEntity()
248
254
//
249
255
256
+ def ' findOneAsLinkEntity() should throw exception when category slug is null' () {
257
+ when :
258
+ service. findOneAsLinkEntity(null , Random . lang())
259
+ then :
260
+ IllegalArgumentException ex = thrown()
261
+ ex. message == ' Category slug must be non null'
262
+ }
263
+
250
264
@Unroll
251
265
def " findOneAsLinkEntity() should throw exception when category slug is '#slug'" (String slug) {
252
266
when :
253
267
service. findOneAsLinkEntity(slug, ' ru' )
254
268
then :
255
- thrown IllegalArgumentException
269
+ IllegalArgumentException ex = thrown()
270
+ ex. message == ' Category slug must be non empty'
256
271
where :
257
272
slug | _
258
273
' ' | _
259
274
' ' | _
260
- null | _
261
275
}
262
276
263
277
def " findOneAsLinkEntity() should pass arguments to dao" () {
@@ -298,7 +312,8 @@ class CategoryServiceImplTest extends Specification {
298
312
when :
299
313
service. countCategoriesOf(null )
300
314
then :
301
- thrown IllegalArgumentException
315
+ IllegalArgumentException ex = thrown()
316
+ ex. message == ' Collection id must be non null'
302
317
}
303
318
304
319
def " countCategoriesOf() should pass arguments to dao" () {
@@ -318,7 +333,8 @@ class CategoryServiceImplTest extends Specification {
318
333
when :
319
334
service. countBySlug(null )
320
335
then :
321
- thrown IllegalArgumentException
336
+ IllegalArgumentException ex = thrown()
337
+ ex. message == ' Category slug must be non null'
322
338
}
323
339
324
340
def " countBySlug() should call dao" () {
@@ -338,7 +354,8 @@ class CategoryServiceImplTest extends Specification {
338
354
when :
339
355
service. countByName(null )
340
356
then :
341
- thrown IllegalArgumentException
357
+ IllegalArgumentException ex = thrown()
358
+ ex. message == ' Name must be non null'
342
359
}
343
360
344
361
def " countByName() should call dao" () {
@@ -365,7 +382,8 @@ class CategoryServiceImplTest extends Specification {
365
382
when :
366
383
service. countByNameRu(null )
367
384
then :
368
- thrown IllegalArgumentException
385
+ IllegalArgumentException ex = thrown()
386
+ ex. message == ' Name in Russian must be non null'
369
387
}
370
388
371
389
def " countByNameRu() should call dao" () {
@@ -392,7 +410,8 @@ class CategoryServiceImplTest extends Specification {
392
410
when :
393
411
service. countAddedSince(null )
394
412
then :
395
- thrown IllegalArgumentException
413
+ IllegalArgumentException ex = thrown()
414
+ ex. message == ' Date must be non null'
396
415
}
397
416
398
417
def " countAddedSince() should invoke dao, pass argument and return result from dao" () {
@@ -416,7 +435,8 @@ class CategoryServiceImplTest extends Specification {
416
435
when :
417
436
service. countUntranslatedNamesSince(null )
418
437
then :
419
- thrown IllegalArgumentException
438
+ IllegalArgumentException ex = thrown()
439
+ ex. message == ' Date must be non null'
420
440
}
421
441
422
442
def " countUntranslatedNamesSince() should invoke dao, pass argument and return result from dao" () {
@@ -440,7 +460,8 @@ class CategoryServiceImplTest extends Specification {
440
460
when :
441
461
service. getStatisticsOf(null , ' whatever' )
442
462
then :
443
- thrown IllegalArgumentException
463
+ IllegalArgumentException ex = thrown()
464
+ ex. message == ' Collection id must be non null'
444
465
}
445
466
446
467
def " getStatisticsOf() should pass arguments to dao" () {
@@ -462,7 +483,8 @@ class CategoryServiceImplTest extends Specification {
462
483
when :
463
484
service. suggestCategoryForUser(null )
464
485
then :
465
- thrown IllegalArgumentException
486
+ IllegalArgumentException ex = thrown()
487
+ ex. message == ' User id must be non null'
466
488
}
467
489
468
490
def ' suggestCategoryForUser() should return category of the last created series' () {
0 commit comments