-
Notifications
You must be signed in to change notification settings - Fork 1
/
PersonDAOSpec.groovy
53 lines (42 loc) · 1.29 KB
/
PersonDAOSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import groovy.sql.Sql
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
class PersonDAOSpec extends Specification {
@Shared PersonDAO dao = JdbcPersonDAO.instance
@Shared Sql sql = Sql.newInstance(url:'jdbc:h2:db', driver:'org.h2.Driver')
def 'findAll returns all people'() {
when:
def people = dao.findAll()
then:
5 == people.size()
['Archer', 'Picard', 'Kirk', 'Sisko', 'Janeway'].each {
people*.last.contains(it)
}
}
@Unroll
def 'findById returns #first #last with id #id'() {
expect:
Person p = dao.findById(id)
p.first == first
p.last == last
where:
[id, first, last] << sql.rows('select id, first, last from people')
}
def 'insert and delete a new person'() {
Person taggart = new Person(first:'Peter Quincy', last:'Taggart')
when:
dao.create(taggart)
then:
dao.findAll().size() == old(dao.findAll().size()) + 1
taggart.id
when:
dao.delete(taggart.id)
then:
dao.findAll().size() == old(dao.findAll().size()) - 1
}
def 'findByName returns correct person'() {
expect:
dao.findByLastName('a').size() == 3
}
}