17
17
*/
18
18
package ru.mystamps.web.service
19
19
20
- import static io.qala.datagen.RandomShortApi.nullOrBlank
21
-
22
20
import org.slf4j.helpers.NOPLogger
23
21
24
22
import spock.lang.Specification
23
+ import spock.lang.Unroll
25
24
26
25
import ru.mystamps.web.dao.StampsCatalogDao
27
26
import ru.mystamps.web.tests.Random
@@ -45,14 +44,16 @@ class StampsCatalogServiceImplTest extends Specification {
45
44
when :
46
45
service. add(null )
47
46
then :
48
- thrown IllegalArgumentException
47
+ IllegalArgumentException ex = thrown()
48
+ ex. message == ' TestCatalog numbers must be non null'
49
49
}
50
50
51
51
def " add() should throw exception when numbers is empty" () {
52
52
when :
53
53
service. add([] as Set )
54
54
then :
55
- thrown IllegalArgumentException
55
+ IllegalArgumentException ex = thrown()
56
+ ex. message == ' TestCatalog numbers must be non empty'
56
57
}
57
58
58
59
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -76,21 +77,24 @@ class StampsCatalogServiceImplTest extends Specification {
76
77
when :
77
78
service. addToSeries(null , [ ' 1' , ' 2' ] as Set )
78
79
then :
79
- thrown IllegalArgumentException
80
+ IllegalArgumentException ex = thrown()
81
+ ex. message == ' Series id must be non null'
80
82
}
81
83
82
84
def " addToSeries() should throw exception when numbers is null" () {
83
85
when :
84
86
service. addToSeries(123 , null )
85
87
then :
86
- thrown IllegalArgumentException
88
+ IllegalArgumentException ex = thrown()
89
+ ex. message == ' TestCatalog numbers must be non null'
87
90
}
88
91
89
92
def " addToSeries() should throw exception when numbers is empty" () {
90
93
when :
91
94
service. addToSeries(123 , [] as Set )
92
95
then :
93
- thrown IllegalArgumentException
96
+ IllegalArgumentException ex = thrown()
97
+ ex. message == ' TestCatalog numbers must be non empty'
94
98
}
95
99
96
100
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -118,7 +122,8 @@ class StampsCatalogServiceImplTest extends Specification {
118
122
when :
119
123
service. findBySeriesId(null )
120
124
then :
121
- thrown IllegalArgumentException
125
+ IllegalArgumentException ex = thrown()
126
+ ex. message == ' Series id must be non null'
122
127
}
123
128
124
129
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
@@ -142,11 +147,25 @@ class StampsCatalogServiceImplTest extends Specification {
142
147
// Tests for findSeriesIdsByNumber()
143
148
//
144
149
145
- def ' findSeriesIdsByNumber() should throw exception when argument is null, empty or blank' () {
150
+ def ' findSeriesIdsByNumber() should throw exception when argument is null' () {
151
+ when :
152
+ service. findSeriesIdsByNumber(null )
153
+ then :
154
+ IllegalArgumentException ex = thrown()
155
+ ex. message == ' TestCatalog number must be non null'
156
+ }
157
+
158
+ @Unroll
159
+ def " findSeriesIdsByNumber() should throw exception when argument is '#catalogNumber'" (String catalogNumber) {
146
160
when :
147
- service. findSeriesIdsByNumber(nullOrBlank() )
161
+ service. findSeriesIdsByNumber(catalogNumber )
148
162
then :
149
- thrown IllegalArgumentException
163
+ IllegalArgumentException ex = thrown()
164
+ ex. message == ' TestCatalog number must be non-blank'
165
+ where :
166
+ catalogNumber | _
167
+ ' ' | _
168
+ ' ' | _
150
169
}
151
170
152
171
def ' findSeriesIdsByNumber() should invoke dao and return its result' () {
0 commit comments