Skip to content

Commit 9243c12

Browse files
committed
SeriesSalesServiceImpl.add(): add more checks for non-nullable fields.
No functional changes.
1 parent 256163d commit 9243c12

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class SeriesSalesServiceImpl implements SeriesSalesService {
4747
@PreAuthorize(HasAuthority.ADD_SERIES_SALES)
4848
public void add(AddSeriesSalesDto dto, Integer seriesId, Integer userId) {
4949
Validate.isTrue(dto != null, "DTO must be non null");
50+
Validate.isTrue(dto.getSellerId() != null, "Seller id must be non null");
51+
Validate.isTrue(dto.getPrice() != null, "Price must be non null");
5052
Validate.isTrue(dto.getCurrency() != null, "Currency must be non null");
5153
Validate.isTrue(seriesId != null, "Series id must be non null");
5254
Validate.isTrue(userId != null, "Current user id must be non null");

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class SeriesSalesServiceImplTest extends Specification {
3636

3737
def setup() {
3838
form = new AddSeriesSalesForm()
39+
form.setSellerId(7)
40+
form.setPrice(new BigDecimal('14'))
3941
form.setCurrency(Currency.EUR)
4042
}
4143

@@ -50,9 +52,29 @@ class SeriesSalesServiceImplTest extends Specification {
5052
thrown IllegalArgumentException
5153
}
5254

55+
def 'add() should throw exception when seller id is null'() {
56+
given:
57+
form.setSellerId(null)
58+
when:
59+
service.add(form, 123, 456)
60+
then:
61+
thrown IllegalArgumentException
62+
}
63+
64+
def 'add() should throw exception when price is null'() {
65+
given:
66+
form.setPrice(null)
67+
when:
68+
service.add(form, 123, 456)
69+
then:
70+
thrown IllegalArgumentException
71+
}
72+
5373
def 'add() should throw exception when currency is null'() {
74+
given:
75+
form.setCurrency(null)
5476
when:
55-
service.add(new AddSeriesSalesForm(), 123, 456)
77+
service.add(form, 123, 456)
5678
then:
5779
thrown IllegalArgumentException
5880
}

0 commit comments

Comments
 (0)