Skip to content

Commit 4556cf1

Browse files
committed
CategoryServiceImplTest.getStatisticsOf(): add unit tests.
Fix #64
1 parent df0bcaf commit 4556cf1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

100644100755
+45
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import spock.lang.Unroll
2323
import ru.mystamps.web.dao.CategoryDao
2424
import ru.mystamps.web.dao.JdbcCategoryDao
2525
import ru.mystamps.web.entity.Category
26+
import ru.mystamps.web.entity.Collection
2627
import ru.mystamps.web.entity.User
2728
import ru.mystamps.web.model.AddCategoryForm
2829
import ru.mystamps.web.service.dto.SelectEntityDto
@@ -266,4 +267,48 @@ class CategoryServiceImplTest extends Specification {
266267
})
267268
}
268269

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+
269314
}

0 commit comments

Comments
 (0)