File tree 3 files changed +42
-0
lines changed
groovy/ru/mystamps/web/service
3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import spock.lang.Unroll
29
29
30
30
import ru.mystamps.web.dao.CategoryDao
31
31
import ru.mystamps.web.dao.dto.AddCategoryDbDto
32
+ import ru.mystamps.web.dao.dto.CategoryDto
32
33
import ru.mystamps.web.controller.dto.AddCategoryForm
33
34
import ru.mystamps.web.dao.dto.LinkEntityDto
34
35
import ru.mystamps.web.tests.DateUtils
@@ -240,6 +241,26 @@ class CategoryServiceImplTest extends Specification {
240
241
null | _
241
242
}
242
243
244
+ //
245
+ // Tests for findCategoriesWithParents()
246
+ //
247
+
248
+ @SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
249
+ def ' findCategoriesWithParents() should invoke dao and return its result' () {
250
+ given :
251
+ String expectedLang = nullOr(Random . lang())
252
+ List<CategoryDto > expectedResult = Random . listOfCategoryDto()
253
+ when :
254
+ List<CategoryDto > result = service. findCategoriesWithParents(expectedLang)
255
+ then :
256
+ 1 * categoryDao. findCategoriesWithParents({ String lang ->
257
+ assert lang == expectedLang
258
+ return true
259
+ }) >> expectedResult
260
+ and :
261
+ result == expectedResult
262
+ }
263
+
243
264
//
244
265
// Tests for findOneAsLinkEntity()
245
266
//
Original file line number Diff line number Diff line change @@ -201,4 +201,12 @@ public static ParsedDataDto createParsedDataDto() {
201
201
);
202
202
}
203
203
204
+ public static CategoryDto createCategoryDto () {
205
+ String name = Random .categoryName ();
206
+ String slug = SlugUtils .slugify (name );
207
+ // @todo #548 Introduce name generator for top categories
208
+ String parentName = Random .categoryName ();
209
+ return new CategoryDto (name , slug , parentName );
210
+ }
211
+
204
212
}
Original file line number Diff line number Diff line change 24
24
25
25
import io .qala .datagen .RandomShortApi ;
26
26
27
+ import ru .mystamps .web .dao .dto .CategoryDto ;
27
28
import ru .mystamps .web .dao .dto .EntityWithIdDto ;
28
29
import ru .mystamps .web .service .TestObjects ;
29
30
import ru .mystamps .web .validation .ValidationRules ;
@@ -132,4 +133,16 @@ public static List<EntityWithIdDto> listOfEntityWithIdDto() {
132
133
);
133
134
}
134
135
136
+ public static List <CategoryDto > listOfCategoryDto () {
137
+ final int minSize = 1 ;
138
+ final int maxSize = 3 ;
139
+ int size = integer (minSize , maxSize );
140
+ return sampleMultiple (
141
+ size ,
142
+ TestObjects .createCategoryDto (),
143
+ TestObjects .createCategoryDto (),
144
+ TestObjects .createCategoryDto ()
145
+ );
146
+ }
147
+
135
148
}
You can’t perform that action at this time.
0 commit comments