@@ -22,26 +22,23 @@ import org.springframework.web.multipart.MultipartFile
22
22
import spock.lang.Specification
23
23
import spock.lang.Unroll
24
24
25
- import ru.mystamps.web.dao.JdbcImageDao
25
+ import ru.mystamps.web.dao.ImageDao
26
26
import ru.mystamps.web.dao.dto.ImageDto
27
27
import ru.mystamps.web.dao.dto.ImageInfoDto
28
28
import ru.mystamps.web.service.exception.ImagePersistenceException
29
29
30
30
class ImageServiceImplTest extends Specification {
31
31
32
- private JdbcImageDao jdbcImageDao = Mock ()
32
+ private ImageDao imageDao = Mock ()
33
33
private MultipartFile multipartFile = Mock ()
34
34
private ImagePersistenceStrategy imagePersistenceStrategy = Mock ()
35
35
36
- private ImageService service = new ImageServiceImpl (
37
- imagePersistenceStrategy,
38
- jdbcImageDao
39
- )
36
+ private ImageService service = new ImageServiceImpl (imagePersistenceStrategy, imageDao)
40
37
41
38
def setup () {
42
39
multipartFile. getSize() >> 1024L
43
40
multipartFile. getContentType() >> ' image/png'
44
- jdbcImageDao . add(_ as String ) >> 17
41
+ imageDao . add(_ as String ) >> 17
45
42
}
46
43
47
44
//
@@ -86,7 +83,7 @@ class ImageServiceImplTest extends Specification {
86
83
when :
87
84
service. save(multipartFile)
88
85
then :
89
- 1 * jdbcImageDao . add(_ as String ) >> 18
86
+ 1 * imageDao . add(_ as String ) >> 18
90
87
}
91
88
92
89
@Unroll
@@ -96,7 +93,7 @@ class ImageServiceImplTest extends Specification {
96
93
then :
97
94
multipartFile. getContentType() >> contentType
98
95
and :
99
- 1 * jdbcImageDao . add({ String type ->
96
+ 1 * imageDao . add({ String type ->
100
97
assert type == expectedType
101
98
return true
102
99
}) >> 19
@@ -112,7 +109,7 @@ class ImageServiceImplTest extends Specification {
112
109
when :
113
110
service. save(multipartFile)
114
111
then :
115
- jdbcImageDao . add(_ as String ) >> null
112
+ imageDao . add(_ as String ) >> null
116
113
and :
117
114
0 * imagePersistenceStrategy. save(_ as MultipartFile , _ as ImageInfoDto )
118
115
and :
@@ -125,7 +122,7 @@ class ImageServiceImplTest extends Specification {
125
122
when :
126
123
String url = service. save(multipartFile)
127
124
then :
128
- jdbcImageDao . add(_ as String ) >> image. id
125
+ imageDao . add(_ as String ) >> image. id
129
126
and :
130
127
1 * imagePersistenceStrategy. save({ MultipartFile passedFile ->
131
128
assert passedFile == multipartFile
@@ -143,7 +140,7 @@ class ImageServiceImplTest extends Specification {
143
140
when :
144
141
Integer actualImageId = service. save(multipartFile)
145
142
then :
146
- jdbcImageDao . add(_ as String ) >> expectedImageId
143
+ imageDao . add(_ as String ) >> expectedImageId
147
144
and :
148
145
actualImageId == expectedImageId
149
146
}
@@ -169,7 +166,7 @@ class ImageServiceImplTest extends Specification {
169
166
when :
170
167
service. get(7 )
171
168
then :
172
- 1 * jdbcImageDao . findById({ Integer imageId ->
169
+ 1 * imageDao . findById({ Integer imageId ->
173
170
assert imageId == 7
174
171
return true
175
172
})
@@ -179,7 +176,7 @@ class ImageServiceImplTest extends Specification {
179
176
when :
180
177
ImageDto image = service. get(9 )
181
178
then :
182
- jdbcImageDao . findById(_ as Integer ) >> null
179
+ imageDao . findById(_ as Integer ) >> null
183
180
and :
184
181
0 * imagePersistenceStrategy. get(_ as ImageInfoDto )
185
182
and :
@@ -190,7 +187,7 @@ class ImageServiceImplTest extends Specification {
190
187
given :
191
188
ImageInfoDto expectedImage = TestObjects . createImageInfoDto()
192
189
and :
193
- jdbcImageDao . findById(_ as Integer ) >> expectedImage
190
+ imageDao . findById(_ as Integer ) >> expectedImage
194
191
and :
195
192
ImageDto expectedImageDto = TestObjects . createDbImageDto()
196
193
when :
@@ -207,7 +204,7 @@ class ImageServiceImplTest extends Specification {
207
204
208
205
def " get() should return null when strategy returned null" () {
209
206
given :
210
- jdbcImageDao . findById(_ as Integer ) >> TestObjects . createImageInfoDto()
207
+ imageDao . findById(_ as Integer ) >> TestObjects . createImageInfoDto()
211
208
and :
212
209
imagePersistenceStrategy. get(_ as ImageInfoDto ) >> null
213
210
when :
0 commit comments