Skip to content

Commit df0bcaf

Browse files
committed
CountryServiceImplTest.getStatisticsOf(): add unit tests.
Fix #65
1 parent 3f715f3 commit df0bcaf

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

+45
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import spock.lang.Unroll
2323
import ru.mystamps.web.dao.CountryDao
2424
import ru.mystamps.web.dao.JdbcCountryDao
2525
import ru.mystamps.web.entity.Country
26+
import ru.mystamps.web.entity.Collection
2627
import ru.mystamps.web.entity.User
2728
import ru.mystamps.web.model.AddCountryForm
2829
import ru.mystamps.web.service.dto.SelectEntityDto
@@ -266,4 +267,48 @@ class CountryServiceImplTest 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 = 17
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 * jdbcCountryDao.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)