Skip to content

Commit 4190c9c

Browse files
committed
CollectionServiceImplTest: simplify code by replacing closures with expected values.
No functional changes.
1 parent 4ab1cfc commit 4190c9c

File tree

1 file changed

+20
-51
lines changed

1 file changed

+20
-51
lines changed

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

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,15 @@ class CollectionServiceImplTest extends Specification {
133133
when:
134134
service.addToCollection(expectedUserId, expectedSeriesId)
135135
then:
136-
1 * collectionDao.addSeriesToUserCollection({ Integer userId ->
137-
assert userId == expectedUserId
138-
return true
139-
}, { Integer seriesId ->
140-
assert seriesId == expectedSeriesId
141-
return true
142-
})
136+
1 * collectionDao.addSeriesToUserCollection(expectedUserId, expectedSeriesId)
143137
and:
144-
1 * collectionDao.markAsModified({ Integer userId ->
145-
assert userId == expectedUserId
146-
return true
147-
}, { Date updatedAt ->
148-
assert DateUtils.roughlyEqual(updatedAt, new Date())
149-
return true
150-
})
138+
1 * collectionDao.markAsModified(
139+
expectedUserId,
140+
{ Date updatedAt ->
141+
assert DateUtils.roughlyEqual(updatedAt, new Date())
142+
return true
143+
}
144+
)
151145
}
152146

153147
//
@@ -176,21 +170,15 @@ class CollectionServiceImplTest extends Specification {
176170
when:
177171
service.removeFromCollection(expectedUserId, expectedSeriesId)
178172
then:
179-
1 * collectionDao.removeSeriesFromUserCollection({ Integer userId ->
180-
assert userId == expectedUserId
181-
return true
182-
}, { Integer seriesId ->
183-
assert seriesId == expectedSeriesId
184-
return true
185-
})
173+
1 * collectionDao.removeSeriesFromUserCollection(expectedUserId, expectedSeriesId)
186174
and:
187-
1 * collectionDao.markAsModified({ Integer userId ->
188-
assert userId == expectedUserId
189-
return true
190-
}, { Date updatedAt ->
191-
assert DateUtils.roughlyEqual(updatedAt, new Date())
192-
return true
193-
})
175+
1 * collectionDao.markAsModified(
176+
expectedUserId,
177+
{ Date updatedAt ->
178+
assert DateUtils.roughlyEqual(updatedAt, new Date())
179+
return true
180+
}
181+
)
194182
}
195183

196184
//
@@ -215,7 +203,6 @@ class CollectionServiceImplTest extends Specification {
215203
0 * collectionDao.isSeriesInUserCollection(_ as Integer, _ as Integer)
216204
}
217205

218-
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
219206
def 'isSeriesInCollection() should pass arguments to dao'() {
220207
given:
221208
Integer expectedUserId = Random.userId()
@@ -226,13 +213,7 @@ class CollectionServiceImplTest extends Specification {
226213
when:
227214
boolean serviceResult = service.isSeriesInCollection(expectedUserId, expectedSeriesId)
228215
then:
229-
1 * collectionDao.isSeriesInUserCollection({ Integer userId ->
230-
assert userId == expectedUserId
231-
return true
232-
}, { Integer seriesId ->
233-
assert seriesId == expectedSeriesId
234-
return true
235-
}) >> expectedResult
216+
1 * collectionDao.isSeriesInUserCollection(expectedUserId, expectedSeriesId) >> expectedResult
236217
and:
237218
serviceResult == expectedResult
238219
}
@@ -263,18 +244,14 @@ class CollectionServiceImplTest extends Specification {
263244
thrown IllegalArgumentException
264245
}
265246

266-
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
267247
def 'countUpdatedSince() should invoke dao, pass argument and return result from dao'() {
268248
given:
269249
Date expectedDate = new Date()
270250
long expectedResult = 47
271251
when:
272252
long result = service.countUpdatedSince(expectedDate)
273253
then:
274-
1 * collectionDao.countUpdatedSince({ Date date ->
275-
assert date == expectedDate
276-
return true
277-
}) >> expectedResult
254+
1 * collectionDao.countUpdatedSince(expectedDate) >> expectedResult
278255
and:
279256
result == expectedResult
280257
}
@@ -295,17 +272,13 @@ class CollectionServiceImplTest extends Specification {
295272
0 | _
296273
}
297274

298-
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
299275
def 'findRecentlyCreated() should pass arguments to dao'() {
300276
given:
301277
int expectedQuantity = 4
302278
when:
303279
service.findRecentlyCreated(expectedQuantity)
304280
then:
305-
1 * collectionDao.findLastCreated({ int quantity ->
306-
assert expectedQuantity == quantity
307-
return true
308-
}) >> []
281+
1 * collectionDao.findLastCreated(expectedQuantity) >> []
309282
}
310283

311284
//
@@ -319,7 +292,6 @@ class CollectionServiceImplTest extends Specification {
319292
thrown IllegalArgumentException
320293
}
321294

322-
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
323295
def 'findBySlug() should invoke dao, pass argument and return result from dao'() {
324296
given:
325297
String expectedSlug = 'cuba'
@@ -328,10 +300,7 @@ class CollectionServiceImplTest extends Specification {
328300
when:
329301
CollectionInfoDto result = service.findBySlug(expectedSlug)
330302
then:
331-
1 * collectionDao.findCollectionInfoBySlug({ String slug ->
332-
assert slug == expectedSlug
333-
return true
334-
}) >> expectedResult
303+
1 * collectionDao.findCollectionInfoBySlug(expectedSlug) >> expectedResult
335304
and:
336305
result == expectedResult
337306
}

0 commit comments

Comments
 (0)