Skip to content

Commit 021f1c0

Browse files
committed
CollectionServiceImpl.findRecentlyCreated(): add unit tests.
Fix #68
1 parent dfd0f4c commit 021f1c0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright (C) 2009-2015 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.service
19+
20+
import spock.lang.Specification
21+
import spock.lang.Unroll
22+
23+
import ru.mystamps.web.dao.CollectionDao
24+
import ru.mystamps.web.dao.JdbcCollectionDao
25+
26+
class CollectionServiceImplTest extends Specification {
27+
private CollectionDao collectionDao = Mock()
28+
private JdbcCollectionDao jdbcCollectionDao = Mock()
29+
30+
private CollectionService service
31+
32+
def setup() {
33+
service = new CollectionServiceImpl(collectionDao, jdbcCollectionDao)
34+
}
35+
36+
//
37+
// Tests for findRecentlyCreated
38+
//
39+
40+
@Unroll
41+
def "findRecentlyCreated should throw exception when quantity is #quantity"(Integer quantity, Object _) {
42+
when:
43+
service.findRecentlyCreated(quantity)
44+
then:
45+
thrown IllegalArgumentException
46+
where:
47+
quantity | _
48+
-1 | _
49+
0 | _
50+
}
51+
52+
def "findRecentlyCreated should pass arguments to dao"() {
53+
given:
54+
int expectedQuantity = 4
55+
when:
56+
service.findRecentlyCreated(expectedQuantity)
57+
then:
58+
1 * jdbcCollectionDao.findLastCreated({ int quantity ->
59+
assert expectedQuantity == quantity
60+
return true
61+
}) >> []
62+
}
63+
64+
}

0 commit comments

Comments
 (0)