@@ -23,6 +23,7 @@ import spock.lang.Unroll
23
23
import ru.mystamps.web.dao.CategoryDao
24
24
import ru.mystamps.web.dao.JdbcCategoryDao
25
25
import ru.mystamps.web.entity.Category
26
+ import ru.mystamps.web.entity.Collection
26
27
import ru.mystamps.web.entity.User
27
28
import ru.mystamps.web.model.AddCategoryForm
28
29
import ru.mystamps.web.service.dto.SelectEntityDto
@@ -266,4 +267,48 @@ class CategoryServiceImplTest extends Specification {
266
267
})
267
268
}
268
269
270
+ //
271
+ // Tests for getStatisticsOf()
272
+ //
273
+
274
+ def " getStatisticsOf() should throw exception when collection is null" () {
275
+ when :
276
+ service. getStatisticsOf(null , ' whatever' )
277
+ then :
278
+ thrown IllegalArgumentException
279
+ }
280
+
281
+ def " getStatisticsOf() should throw exception when collection id is null" () {
282
+ given :
283
+ Collection collection = Mock ()
284
+ collection. getId() >> null
285
+ when :
286
+ service. getStatisticsOf(collection, ' whatever' )
287
+ then :
288
+ thrown IllegalArgumentException
289
+ }
290
+
291
+ def " getStatisticsOf() should pass arguments to dao" () {
292
+ given :
293
+ Integer expectedCollectionId = 15
294
+ and :
295
+ String expectedLang = ' expected'
296
+ and :
297
+ Collection expectedCollection = Mock ()
298
+ expectedCollection. getId() >> expectedCollectionId
299
+ when :
300
+ service. getStatisticsOf(expectedCollection, expectedLang)
301
+ then :
302
+ 1 * jdbcCategoryDao. getStatisticsOf(
303
+ { Integer collectionId ->
304
+ assert expectedCollectionId == collectionId
305
+ return true
306
+ },
307
+ { String lang ->
308
+ assert expectedLang == lang
309
+ return true
310
+ }
311
+ ) >> null
312
+ }
313
+
269
314
}
0 commit comments