Skip to content

Commit 3a0cc67

Browse files
committed
SeriesInfoExtractorServiceImpl.extractQuantity(): respect MAX_STAMPS_IN_SERIES.
Fix #789
1 parent 2f23265 commit 3a0cc67

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/main/java/ru/mystamps/web/service/SeriesInfoExtractorServiceImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ protected Integer extractReleaseYear(String fragment) {
227227
return null;
228228
}
229229

230-
// @todo #781 SeriesInfoExtractorServiceImpl.extractQuantity() respect MAX_STAMPS_IN_SERIES
231230
protected Integer extractQuantity(String fragment) {
232231
if (StringUtils.isBlank(fragment)) {
233232
return null;
@@ -237,9 +236,11 @@ protected Integer extractQuantity(String fragment) {
237236

238237
Matcher matcher = NUMBER_OF_STAMPS_REGEXP.matcher(fragment);
239238
if (matcher.find()) {
240-
String quantity = matcher.group("quantity");
241-
log.debug("Quantity is {}", quantity);
242-
return Integer.valueOf(quantity);
239+
Integer quantity = Integer.valueOf(matcher.group("quantity"));
240+
if (quantity <= ValidationRules.MAX_STAMPS_IN_SERIES) {
241+
log.debug("Quantity is {}", quantity);
242+
return quantity;
243+
}
243244
}
244245

245246
log.debug("Could not extract quantity from a fragment");

src/test/groovy/ru/mystamps/web/service/SeriesInfoExtractorServiceImplTest.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import static io.qala.datagen.RandomShortApi.nullOrBlank
2222
import static io.qala.datagen.RandomValue.between
2323

2424
import static ru.mystamps.web.service.SeriesInfoExtractorServiceImpl.MAX_SUPPORTED_RELEASE_YEAR
25+
import static ru.mystamps.web.validation.ValidationRules.MAX_STAMPS_IN_SERIES
2526

2627
import java.time.Year
2728

@@ -334,8 +335,9 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
334335
expect:
335336
service.extractQuantity(fragment) == null
336337
where:
337-
fragment | _
338-
'0 марок' | _
338+
fragment | _
339+
'0 марок' | _
340+
(MAX_STAMPS_IN_SERIES + 1) + ' марок' | _
339341
}
340342

341343
@Unroll

0 commit comments

Comments
 (0)