@@ -22,7 +22,6 @@ import spock.lang.Unroll
22
22
23
23
import ru.mystamps.web.dao.JdbcCategoryDao
24
24
import ru.mystamps.web.dao.dto.AddCategoryDbDto
25
- import ru.mystamps.web.entity.User
26
25
import ru.mystamps.web.model.AddCategoryForm
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 CategoryServiceImplTest extends Specification {
34
33
35
34
private AddCategoryForm form
36
- private User user
35
+ private Integer userId = 123
37
36
38
37
private JdbcCategoryDao categoryDao = Mock ()
39
38
private CategoryService service = new CategoryServiceImpl (categoryDao)
@@ -42,8 +41,6 @@ class CategoryServiceImplTest extends Specification {
42
41
form = new AddCategoryForm ()
43
42
form. setName(' Any category name' )
44
43
form. setNameRu(' Любое название категории' )
45
-
46
- user = TestObjects . createUser()
47
44
}
48
45
49
46
//
@@ -52,7 +49,7 @@ class CategoryServiceImplTest 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 CategoryServiceImplTest 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 CategoryServiceImplTest 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 CategoryServiceImplTest 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 CategoryServiceImplTest extends Specification {
104
101
String expectedCategoryName = ' Animals'
105
102
form. setName(expectedCategoryName)
106
103
when :
107
- service. add(form, user )
104
+ service. add(form, userId )
108
105
then :
109
106
1 * categoryDao. add({ AddCategoryDbDto category ->
110
107
assert category?. name == expectedCategoryName
@@ -117,7 +114,7 @@ class CategoryServiceImplTest extends Specification {
117
114
String expectedCategoryName = ' Животные'
118
115
form. setNameRu(expectedCategoryName)
119
116
when :
120
- service. add(form, user )
117
+ service. add(form, userId )
121
118
then :
122
119
1 * categoryDao. add({ AddCategoryDbDto category ->
123
120
assert category?. nameRu == expectedCategoryName
@@ -129,7 +126,7 @@ class CategoryServiceImplTest 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 CategoryServiceImplTest 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 * categoryDao. add({ AddCategoryDbDto category ->
148
145
assert category?. slug == slug
@@ -152,7 +149,7 @@ class CategoryServiceImplTest 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 * categoryDao. add({ AddCategoryDbDto category ->
158
155
assert DateUtils . roughlyEqual(category?. createdAt, new Date ())
@@ -162,7 +159,7 @@ class CategoryServiceImplTest 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 * categoryDao. add({ AddCategoryDbDto category ->
168
165
assert DateUtils . roughlyEqual(category?. updatedAt, new Date ())
@@ -171,21 +168,25 @@ class CategoryServiceImplTest 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 * categoryDao. add({ AddCategoryDbDto category ->
178
- assert category?. createdBy == user . id
177
+ assert category?. 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 = 20
184
185
when :
185
- service. add(form, user )
186
+ service. add(form, expectedUserId )
186
187
then :
187
188
1 * categoryDao. add({ AddCategoryDbDto category ->
188
- assert category?. updatedBy == user . id
189
+ assert category?. updatedBy == expectedUserId
189
190
return true
190
191
}) >> 80
191
192
}
0 commit comments