@@ -22,7 +22,6 @@ import spock.lang.Unroll
22
22
23
23
import ru.mystamps.web.dao.JdbcCountryDao
24
24
import ru.mystamps.web.dao.dto.AddCountryDbDto
25
- import ru.mystamps.web.entity.User
26
25
import ru.mystamps.web.model.AddCountryForm
27
26
import ru.mystamps.web.service.dto.LinkEntityDto
28
27
import ru.mystamps.web.service.dto.SelectEntityDto
@@ -33,7 +32,7 @@ import ru.mystamps.web.util.SlugUtils
33
32
class CountryServiceImplTest extends Specification {
34
33
35
34
private AddCountryForm form
36
- private User user
35
+ private Integer userId = 321
37
36
38
37
private JdbcCountryDao countryDao = Mock ()
39
38
private CountryService service = new CountryServiceImpl (countryDao)
@@ -42,8 +41,6 @@ class CountryServiceImplTest extends Specification {
42
41
form = new AddCountryForm ()
43
42
form. setName(' Any country name' )
44
43
form. setNameRu(' Любое название страны' )
45
-
46
- user = TestObjects . createUser()
47
44
}
48
45
49
46
//
@@ -52,7 +49,7 @@ class CountryServiceImplTest extends Specification {
52
49
53
50
def " add() should throw exception when dto is null" () {
54
51
when :
55
- service. add(null , user )
52
+ service. add(null , userId )
56
53
then :
57
54
thrown IllegalArgumentException
58
55
}
@@ -61,7 +58,7 @@ class CountryServiceImplTest extends Specification {
61
58
given :
62
59
form. setName(null )
63
60
when :
64
- service. add(form, user )
61
+ service. add(form, userId )
65
62
then :
66
63
thrown IllegalArgumentException
67
64
}
@@ -70,7 +67,7 @@ class CountryServiceImplTest extends Specification {
70
67
given :
71
68
form. setNameRu(null )
72
69
when :
73
- service. add(form, user )
70
+ service. add(form, userId )
74
71
then :
75
72
thrown IllegalArgumentException
76
73
}
@@ -94,7 +91,7 @@ class CountryServiceImplTest extends Specification {
94
91
and :
95
92
UrlEntityDto expected = new UrlEntityDto (expectedId, expectedSlug)
96
93
when :
97
- UrlEntityDto actual = service. add(form, user )
94
+ UrlEntityDto actual = service. add(form, userId )
98
95
then :
99
96
actual == expected
100
97
}
@@ -104,7 +101,7 @@ class CountryServiceImplTest extends Specification {
104
101
String expectedCountryName = ' Italy'
105
102
form. setName(expectedCountryName)
106
103
when :
107
- service. add(form, user )
104
+ service. add(form, userId )
108
105
then :
109
106
1 * countryDao. add({ AddCountryDbDto country ->
110
107
assert country?. name == expectedCountryName
@@ -117,7 +114,7 @@ class CountryServiceImplTest extends Specification {
117
114
String expectedCountryName = ' Италия'
118
115
form. setNameRu(expectedCountryName)
119
116
when :
120
- service. add(form, user )
117
+ service. add(form, userId )
121
118
then :
122
119
1 * countryDao. add({ AddCountryDbDto country ->
123
120
assert country?. nameRu == expectedCountryName
@@ -129,7 +126,7 @@ class CountryServiceImplTest extends Specification {
129
126
given :
130
127
form. setName(null )
131
128
when :
132
- service. add(form, user )
129
+ service. add(form, userId )
133
130
then :
134
131
thrown IllegalArgumentException
135
132
}
@@ -142,7 +139,7 @@ class CountryServiceImplTest extends Specification {
142
139
and :
143
140
form. setName(name)
144
141
when :
145
- service. add(form, user )
142
+ service. add(form, userId )
146
143
then :
147
144
1 * countryDao. add({ AddCountryDbDto country ->
148
145
assert country?. slug == slug
@@ -152,7 +149,7 @@ class CountryServiceImplTest extends Specification {
152
149
153
150
def " add() should assign created at to current date" () {
154
151
when :
155
- service. add(form, user )
152
+ service. add(form, userId )
156
153
then :
157
154
1 * countryDao. add({ AddCountryDbDto country ->
158
155
assert DateUtils . roughlyEqual(country?. createdAt, new Date ())
@@ -162,7 +159,7 @@ class CountryServiceImplTest extends Specification {
162
159
163
160
def " add() should assign updated at to current date" () {
164
161
when :
165
- service. add(form, user )
162
+ service. add(form, userId )
166
163
then :
167
164
1 * countryDao. add({ AddCountryDbDto country ->
168
165
assert DateUtils . roughlyEqual(country?. updatedAt, new Date ())
@@ -171,21 +168,25 @@ class CountryServiceImplTest extends Specification {
171
168
}
172
169
173
170
def " add() should assign created by to user" () {
171
+ given :
172
+ Integer expectedUserId = 10
174
173
when :
175
- service. add(form, user )
174
+ service. add(form, expectedUserId )
176
175
then :
177
176
1 * countryDao. add({ AddCountryDbDto country ->
178
- assert country?. createdBy == user . id
177
+ assert country?. createdBy == expectedUserId
179
178
return true
180
179
}) >> 70
181
180
}
182
181
183
182
def " add() should assign updated by to user" () {
183
+ given :
184
+ Integer expectedUserId = 10
184
185
when :
185
- service. add(form, user )
186
+ service. add(form, expectedUserId )
186
187
then :
187
188
1 * countryDao. add({ AddCountryDbDto country ->
188
- assert country?. updatedBy == user . id
189
+ assert country?. updatedBy == expectedUserId
189
190
return true
190
191
}) >> 80
191
192
}
0 commit comments