Skip to content

Commit dd20a0f

Browse files
committed
CollectionServiceImplTest: check not only presence of an exception but also its message.
Addressed to #925 No functional changes.
1 parent 79a1b85 commit dd20a0f

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

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

+32-16
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,26 @@ class CollectionServiceImplTest extends Specification {
5555
when:
5656
service.createCollection(null, 'test-owner-login')
5757
then:
58-
thrown IllegalArgumentException
58+
IllegalArgumentException ex = thrown()
59+
ex.message == 'Owner id must be non null'
5960
}
6061

6162
@SuppressWarnings('FactoryMethodName')
6263
def 'createCollection() should throw exception when owner login is null'() {
6364
when:
6465
service.createCollection(Random.userId(), null)
6566
then:
66-
thrown IllegalArgumentException
67+
IllegalArgumentException ex = thrown()
68+
ex.message == 'Owner login must be non null'
6769
}
6870

6971
@SuppressWarnings('FactoryMethodName')
7072
def 'createCollection() should throw exception when owner login can\'t be converted to slug'() {
7173
when:
7274
service.createCollection(Random.userId(), '')
7375
then:
74-
thrown IllegalArgumentException
76+
IllegalArgumentException ex = thrown()
77+
ex.message == 'Slug for string \'\' must be non empty'
7578
}
7679

7780
@SuppressWarnings(['ClosureAsLastMethodParameter', 'FactoryMethodName', 'UnnecessaryReturnKeyword'])
@@ -121,14 +124,16 @@ class CollectionServiceImplTest extends Specification {
121124
when:
122125
service.addToCollection(null, TestObjects.createAddToCollectionDto())
123126
then:
124-
thrown IllegalArgumentException
127+
IllegalArgumentException ex = thrown()
128+
ex.message == 'User id must be non null'
125129
}
126130

127131
def 'addToCollection() should throw exception when dto is null'() {
128132
when:
129133
service.addToCollection(Random.userId(), null)
130134
then:
131-
thrown IllegalArgumentException
135+
IllegalArgumentException ex = thrown()
136+
ex.message == 'DTO must be non null'
132137
}
133138

134139
def 'addToCollection() should throw exception when number of stamps is null'() {
@@ -138,7 +143,8 @@ class CollectionServiceImplTest extends Specification {
138143
when:
139144
service.addToCollection(Random.userId(), form)
140145
then:
141-
thrown IllegalArgumentException
146+
IllegalArgumentException ex = thrown()
147+
ex.message == 'Number of stamps must be non null'
142148
}
143149

144150
def 'addToCollection() should throw exception when series id is null'() {
@@ -148,7 +154,8 @@ class CollectionServiceImplTest extends Specification {
148154
when:
149155
service.addToCollection(Random.userId(), form)
150156
then:
151-
thrown IllegalArgumentException
157+
IllegalArgumentException ex = thrown()
158+
ex.message == 'Series id must be non null'
152159
}
153160

154161
def 'addToCollection() should throw exception when price is specified without currency'() {
@@ -159,7 +166,8 @@ class CollectionServiceImplTest extends Specification {
159166
when:
160167
service.addToCollection(Random.userId(), form)
161168
then:
162-
thrown IllegalStateException
169+
IllegalStateException ex = thrown()
170+
ex.message == 'Currency must be non null when price is specified'
163171
}
164172

165173
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
@@ -204,14 +212,16 @@ class CollectionServiceImplTest extends Specification {
204212
when:
205213
service.removeFromCollection(null, Random.id())
206214
then:
207-
thrown IllegalArgumentException
215+
IllegalArgumentException ex = thrown()
216+
ex.message == 'User id must be non null'
208217
}
209218

210219
def 'removeFromCollection() should throw exception when series id is null'() {
211220
when:
212221
service.removeFromCollection(Random.userId(), null)
213222
then:
214-
thrown IllegalArgumentException
223+
IllegalArgumentException ex = thrown()
224+
ex.message == 'Series id must be non null'
215225
}
216226

217227
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
@@ -241,7 +251,8 @@ class CollectionServiceImplTest extends Specification {
241251
when:
242252
service.isSeriesInCollection(Random.userId(), null)
243253
then:
244-
thrown IllegalArgumentException
254+
IllegalArgumentException ex = thrown()
255+
ex.message == 'Series id must be non null'
245256
}
246257

247258
def 'isSeriesInCollection() should return false for anonymous'() {
@@ -293,7 +304,8 @@ class CollectionServiceImplTest extends Specification {
293304
when:
294305
service.countUpdatedSince(null)
295306
then:
296-
thrown IllegalArgumentException
307+
IllegalArgumentException ex = thrown()
308+
ex.message == 'Date must be non null'
297309
}
298310

299311
def 'countUpdatedSince() should invoke dao, pass argument and return result from dao'() {
@@ -316,7 +328,8 @@ class CollectionServiceImplTest extends Specification {
316328
when:
317329
service.countStampsOf(null)
318330
then:
319-
thrown IllegalArgumentException
331+
IllegalArgumentException ex = thrown()
332+
ex.message == 'Collection id must be non null'
320333
}
321334

322335
def 'countStampsOf() should pass arguments to dao'() {
@@ -337,7 +350,8 @@ class CollectionServiceImplTest extends Specification {
337350
when:
338351
service.findRecentlyCreated(quantity)
339352
then:
340-
thrown IllegalArgumentException
353+
IllegalArgumentException ex = thrown()
354+
ex.message == 'Quantity must be greater than 0'
341355
where:
342356
quantity | _
343357
-1 | _
@@ -361,7 +375,8 @@ class CollectionServiceImplTest extends Specification {
361375
when:
362376
service.findSeriesInCollection(null, Random.lang())
363377
then:
364-
thrown IllegalArgumentException
378+
IllegalArgumentException ex = thrown()
379+
ex.message == 'Collection id must be non null'
365380
}
366381

367382
def 'findSeriesInCollection() should pass arguments to dao'() {
@@ -383,7 +398,8 @@ class CollectionServiceImplTest extends Specification {
383398
when:
384399
service.findBySlug(null)
385400
then:
386-
thrown IllegalArgumentException
401+
IllegalArgumentException ex = thrown()
402+
ex.message == 'Collection slug must be non null'
387403
}
388404

389405
def 'findBySlug() should invoke dao, pass argument and return result from dao'() {

0 commit comments

Comments
 (0)