Skip to content

Commit a6febfb

Browse files
committed
CatalogUtils.parseCatalogNumbers(): implement parsing of a range of numbers.
Required for #694
1 parent 520bbee commit a6febfb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,30 @@ class CatalogUtilsTest extends Specification {
206206
'2-1' | 'Range must be in an ascending order'
207207
}
208208

209+
def 'parseCatalogNumbers() should return two elements for a range with two numbers'() {
210+
when:
211+
Set<String> numbers = CatalogUtils.parseCatalogNumbers('1-2')
212+
then:
213+
numbers == [ '1', '2' ] as Set
214+
}
215+
216+
@Unroll
217+
def 'parseCatalogNumbers() should throw exception for an invalid value (#numbers)'(
218+
String numbers, String message) {
219+
220+
when:
221+
CatalogUtils.parseCatalogNumbers(numbers)
222+
then:
223+
IllegalArgumentException ex = thrown()
224+
ex.message == message
225+
where:
226+
numbers | message
227+
'1-2-3' | 'Unexpected number of separators found: expected to have only one'
228+
'1-z' | 'Unexpected a non-numeric range found'
229+
'z-2' | 'Unexpected a non-numeric range found'
230+
' 1 - 2 ' | 'Unexpected a non-numeric range found'
231+
'1-1' | 'Range must be in an ascending order'
232+
'2-1' | 'Range must be in an ascending order'
233+
}
234+
209235
}

0 commit comments

Comments
 (0)