@@ -75,6 +75,51 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
75
75
result == expectedResult
76
76
}
77
77
78
+ @SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
79
+ def ' extractCategory() should deduplicate candidates' () {
80
+ given :
81
+ String fragment = ' foo bar foo'
82
+ Set<String > expectedCandidates = [ ' foo' , ' bar' ]
83
+ when :
84
+ service. extractCategory(fragment)
85
+ then :
86
+ 1 * categoryService. findIdsByNames({ Set<String > candidates ->
87
+ assert candidates == expectedCandidates
88
+ return true
89
+ }) >> Random . listOfIntegers()
90
+ }
91
+
92
+ @SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
93
+ def ' extractCategory() should try to search category names with candidate as a prefix' () {
94
+ given :
95
+ List<Integer > expectedResult = Random . listOfIntegers()
96
+ when :
97
+ List<Integer > result = service. extractCategory(' foo1 foo2' )
98
+ then :
99
+ // in order to search by prefix, we shouldn't find anything by name
100
+ 1 * categoryService. findIdsByNames(_ as Set<String > ) >> Collections . emptyList()
101
+ and :
102
+ // the first lookup will find nothing
103
+ 1 * categoryService. findIdsWhenNameStartsWith(' foo1' ) >> Collections . emptyList()
104
+ and :
105
+ // the second lookup will return a result
106
+ 1 * categoryService. findIdsWhenNameStartsWith(' foo2' ) >> expectedResult
107
+ and :
108
+ result == expectedResult
109
+ }
110
+
111
+ @SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
112
+ def ' extractCategory() should return an empty result when nothing has been found' () {
113
+ when :
114
+ List<Integer > result = service. extractCategory(' foo' )
115
+ then :
116
+ 1 * categoryService. findIdsByNames(_ as Set<String > ) >> Collections . emptyList()
117
+ and :
118
+ 1 * categoryService. findIdsWhenNameStartsWith(_ as String ) >> Collections . emptyList()
119
+ and :
120
+ result. isEmpty()
121
+ }
122
+
78
123
//
79
124
// Tests for extractCountry()
80
125
//
@@ -106,6 +151,51 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
106
151
result == expectedResult
107
152
}
108
153
154
+ @SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
155
+ def ' extractCountry() should deduplicate candidates' () {
156
+ given :
157
+ String fragment = ' foo bar foo'
158
+ Set<String > expectedCandidates = [ ' foo' , ' bar' ]
159
+ when :
160
+ service. extractCountry(fragment)
161
+ then :
162
+ 1 * countryService. findIdsByNames({ Set<String > candidates ->
163
+ assert candidates == expectedCandidates
164
+ return true
165
+ }) >> Random . listOfIntegers()
166
+ }
167
+
168
+ @SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
169
+ def ' extractCountry() should try to search country names with candidate as a prefix' () {
170
+ given :
171
+ List<Integer > expectedResult = Random . listOfIntegers()
172
+ when :
173
+ List<Integer > result = service. extractCountry(' bar1 bar2' )
174
+ then :
175
+ // in order to search by prefix, we shouldn't find anything by name
176
+ 1 * countryService. findIdsByNames(_ as Set<String > ) >> Collections . emptyList()
177
+ and :
178
+ // the first lookup will find nothing
179
+ 1 * countryService. findIdsWhenNameStartsWith(' bar1' ) >> Collections . emptyList()
180
+ and :
181
+ // the second lookup will return a result
182
+ 1 * countryService. findIdsWhenNameStartsWith(' bar2' ) >> expectedResult
183
+ and :
184
+ result == expectedResult
185
+ }
186
+
187
+ @SuppressWarnings ([' ClosureAsLastMethodParameter' , ' UnnecessaryReturnKeyword' ])
188
+ def ' extractCountry() should return an empty result when nothing has been found' () {
189
+ when :
190
+ List<Integer > result = service. extractCountry(' foo' )
191
+ then :
192
+ 1 * countryService. findIdsByNames(_ as Set<String > ) >> Collections . emptyList()
193
+ and :
194
+ 1 * countryService. findIdsWhenNameStartsWith(_ as String ) >> Collections . emptyList()
195
+ and :
196
+ result. isEmpty()
197
+ }
198
+
109
199
//
110
200
// Tests for extractReleaseYear()
111
201
//
0 commit comments