18
18
package ru.mystamps.web.service
19
19
20
20
import static io.qala.datagen.RandomShortApi.bool
21
+ import static io.qala.datagen.RandomShortApi.nullOr
21
22
22
23
import org.slf4j.helpers.NOPLogger
23
24
24
25
import spock.lang.Specification
25
26
26
27
import ru.mystamps.web.dao.TransactionParticipantDao
27
28
import ru.mystamps.web.dao.dto.AddParticipantDbDto
29
+ import ru.mystamps.web.dao.dto.EntityWithIdDto
28
30
import ru.mystamps.web.controller.dto.AddParticipantForm
29
31
import ru.mystamps.web.tests.Random
30
32
@@ -87,14 +89,16 @@ class TransactionParticipantServiceImplTest extends Specification {
87
89
@SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
88
90
def ' add() should create participant' () {
89
91
given :
90
- String expectedName = Random . participantName()
91
- String expectedUrl = Random . url()
92
- Boolean expectedBuyer = bool()
93
- Boolean expectedSeller = bool()
92
+ String expectedName = Random . participantName()
93
+ String expectedUrl = Random . url()
94
+ Integer expectedGroupId = nullOr(Random . id())
95
+ Boolean expectedBuyer = bool()
96
+ Boolean expectedSeller = bool()
94
97
and :
95
98
AddParticipantForm form = new AddParticipantForm ()
96
99
form. setName(expectedName)
97
100
form. setUrl(expectedUrl)
101
+ form. setGroupId(expectedGroupId)
98
102
form. setBuyer(expectedBuyer)
99
103
form. setSeller(expectedSeller)
100
104
when :
@@ -103,10 +107,26 @@ class TransactionParticipantServiceImplTest extends Specification {
103
107
1 * transactionParticipantDao. add({ AddParticipantDbDto participant ->
104
108
assert participant?. name == expectedName
105
109
assert participant?. url == expectedUrl
110
+ assert participant?. groupId == expectedGroupId
106
111
assert participant?. buyer == expectedBuyer
107
112
assert participant?. seller == expectedSeller
108
113
return true
109
114
})
110
115
}
111
116
117
+ //
118
+ // Tests for findAllGroups()
119
+ //
120
+
121
+ def ' findAllGroups() should invoke dao and return its result' () {
122
+ given :
123
+ List<EntityWithIdDto > expectedResult = Random . listOfEntityWithIdDto()
124
+ when :
125
+ List<EntityWithIdDto > result = service. findAllGroups()
126
+ then :
127
+ 1 * transactionParticipantDao. findAllGroups() >> expectedResult
128
+ and :
129
+ result == expectedResult
130
+ }
131
+
112
132
}
0 commit comments