Skip to content

Commit 133447f

Browse files
committed
add bean validation for ScaledBigDecimal
1 parent cbe67a6 commit 133447f

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

src/main/java/it/aboutbits/springboot/testing/validation/core/BaseValidationAssert.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package it.aboutbits.springboot.testing.validation.core;
22

3+
import it.aboutbits.springboot.toolbox.type.CustomType;
34
import lombok.AccessLevel;
45
import lombok.Getter;
56
import lombok.NonNull;
@@ -16,7 +17,11 @@ public abstract class BaseValidationAssert<R extends BaseRuleBuilder<?>> {
1617
@Getter(AccessLevel.PROTECTED)
1718
private final R ruleBuilder;
1819

19-
protected static final Set<Class<?>> NON_BEAN_TYPES = new HashSet<>();
20+
protected static final Set<Class<?>> NON_BEAN_TYPES = new HashSet<>(
21+
Set.of(
22+
CustomType.class
23+
)
24+
);
2025

2126
private Object parameterUnderTest;
2227

src/test/java/it/aboutbits/springboot/testing/validation/ValidationAssertTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import it.aboutbits.springboot.testing.validation.core.BaseRuleBuilder;
44
import it.aboutbits.springboot.testing.validation.core.BaseValidationAssert;
5+
import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal;
56
import jakarta.validation.Valid;
67
import jakarta.validation.constraints.Future;
78
import jakarta.validation.constraints.Max;
@@ -42,6 +43,8 @@ public record SomeValidParameter(
4243
double biggerThanDouble,
4344
@Min(5)
4445
BigDecimal biggerThanBigDecimal,
46+
@Min(5)
47+
ScaledBigDecimal biggerThanScaledBigDecimal,
4548
@Max(5)
4649
int lessThanInt,
4750
@Max(5)
@@ -52,6 +55,8 @@ public record SomeValidParameter(
5255
double lessThanDouble,
5356
@Max(5)
5457
BigDecimal lessThanBigDecimal,
58+
@Max(5)
59+
ScaledBigDecimal lessThanScaledBigDecimal,
5560
@Min(-3)
5661
@Max(5)
5762
int betweenInt,
@@ -67,6 +72,9 @@ public record SomeValidParameter(
6772
@Min(-3)
6873
@Max(5)
6974
BigDecimal betweenBigDecimal,
75+
@Min(-3)
76+
@Max(5)
77+
ScaledBigDecimal betweenScaledBigDecimal,
7078
@Positive
7179
int positiveInt,
7280
@Positive
@@ -77,6 +85,8 @@ public record SomeValidParameter(
7785
double positiveDouble,
7886
@Positive
7987
BigDecimal positiveBigDecimal,
88+
@Positive
89+
ScaledBigDecimal positiveScaledBigDecimal,
8090
@Negative
8191
int negativeInt,
8292
@Negative
@@ -87,6 +97,8 @@ public record SomeValidParameter(
8797
double negativeDouble,
8898
@Negative
8999
BigDecimal negativeBigDecimal,
100+
@Negative
101+
ScaledBigDecimal negativeScaledBigDecimal,
90102
@PositiveOrZero
91103
int positiveOrZeroInt,
92104
@PositiveOrZero
@@ -97,6 +109,8 @@ public record SomeValidParameter(
97109
double positiveOrZeroDouble,
98110
@PositiveOrZero
99111
BigDecimal positiveOrZeroBigDecimal,
112+
@PositiveOrZero
113+
ScaledBigDecimal positiveOrZeroScaledBigDecimal,
100114
@NegativeOrZero
101115
int negativeOrZeroInt,
102116
@NegativeOrZero
@@ -107,6 +121,8 @@ public record SomeValidParameter(
107121
double negativeOrZeroDouble,
108122
@NegativeOrZero
109123
BigDecimal negativeOrZeroBigDecimal,
124+
@NegativeOrZero
125+
ScaledBigDecimal negativeOrZeroScaledBigDecimal,
110126
@Future
111127
LocalDate futureDate,
112128
@Future
@@ -142,36 +158,43 @@ void testWithBeanValidation() {
142158
.min("biggerThanFloat", 5)
143159
.min("biggerThanDouble", 5)
144160
.min("biggerThanBigDecimal", 5)
161+
.min("biggerThanScaledBigDecimal", 5)
145162
.max("lessThanInt", 5)
146163
.max("lessThanLong", 5)
147164
.max("lessThanFloat", 5)
148165
.max("lessThanDouble", 5)
149166
.max("lessThanBigDecimal", 5)
167+
.max("lessThanScaledBigDecimal", 5)
150168
.positive("positiveInt")
151169
.positive("positiveLong")
152170
.positive("positiveFloat")
153171
.positive("positiveDouble")
154172
.positive("positiveBigDecimal")
173+
.positive("positiveScaledBigDecimal")
155174
.negative("negativeInt")
156175
.negative("negativeLong")
157176
.negative("negativeFloat")
158177
.negative("negativeDouble")
159178
.negative("negativeBigDecimal")
179+
.negative("negativeScaledBigDecimal")
160180
.between("betweenInt", -3, 5)
161181
.between("betweenLong", -3, 5)
162182
.between("betweenFloat", -3, 5)
163183
.between("betweenDouble", -3, 5)
164184
.between("betweenBigDecimal", -3, 5)
185+
.between("betweenScaledBigDecimal", -3, 5)
165186
.positiveOrZero("positiveOrZeroInt")
166187
.positiveOrZero("positiveOrZeroLong")
167188
.positiveOrZero("positiveOrZeroFloat")
168189
.positiveOrZero("positiveOrZeroDouble")
169190
.positiveOrZero("positiveOrZeroBigDecimal")
191+
.positiveOrZero("positiveOrZeroScaledBigDecimal")
170192
.negativeOrZero("negativeOrZeroInt")
171193
.negativeOrZero("negativeOrZeroLong")
172194
.negativeOrZero("negativeOrZeroFloat")
173195
.negativeOrZero("negativeOrZeroDouble")
174196
.negativeOrZero("negativeOrZeroBigDecimal")
197+
.negativeOrZero("negativeOrZeroScaledBigDecimal")
175198
.future("futureDate")
176199
.future("futureDateTime")
177200
.future("futureOffsetDateTime")
@@ -200,36 +223,43 @@ void invalidParameter_shouldFail() {
200223
.min("biggerThanFloat", 5)
201224
.min("biggerThanDouble", 5)
202225
.min("biggerThanBigDecimal", 5)
226+
.min("biggerThanScaledBigDecimal", 5)
203227
.max("lessThanInt", 5)
204228
.max("lessThanLong", 5)
205229
.max("lessThanFloat", 5)
206230
.max("lessThanDouble", 5)
207231
.max("lessThanBigDecimal", 5)
232+
.max("lessThanScaledBigDecimal", 5)
208233
.positive("positiveInt")
209234
.positive("positiveLong")
210235
.positive("positiveFloat")
211236
.positive("positiveDouble")
212237
.positive("positiveBigDecimal")
238+
.positive("positiveScaledBigDecimal")
213239
.negative("negativeInt")
214240
.negative("negativeLong")
215241
.negative("negativeFloat")
216242
.negative("negativeDouble")
217243
.negative("negativeBigDecimal")
244+
.negative("negativeScaledBigDecimal")
218245
.between("betweenInt", -3, 5)
219246
.between("betweenLong", -3, 5)
220247
.between("betweenFloat", -3, 5)
221248
.between("betweenDouble", -3, 5)
222249
.between("betweenBigDecimal", -3, 5)
250+
.between("betweenScaledBigDecimal", -3, 5)
223251
.positiveOrZero("positiveOrZeroInt")
224252
.positiveOrZero("positiveOrZeroLong")
225253
.positiveOrZero("positiveOrZeroFloat")
226254
.positiveOrZero("positiveOrZeroDouble")
227255
.positiveOrZero("positiveOrZeroBigDecimal")
256+
.positiveOrZero("positiveOrZeroScaledBigDecimal")
228257
.negativeOrZero("negativeOrZeroInt")
229258
.negativeOrZero("negativeOrZeroLong")
230259
.negativeOrZero("negativeOrZeroFloat")
231260
.negativeOrZero("negativeOrZeroDouble")
232261
.negativeOrZero("negativeOrZeroBigDecimal")
262+
.negativeOrZero("negativeOrZeroScaledBigDecimal")
233263
.future("futureDate")
234264
.future("futureDateTime")
235265
.future("futureOffsetDateTime")
@@ -256,36 +286,43 @@ void propertyMissingRule_shouldFail() {
256286
.min("biggerThanFloat", 5)
257287
.min("biggerThanDouble", 5)
258288
.min("biggerThanBigDecimal", 5)
289+
.min("biggerThanScaledBigDecimal", 5)
259290
.max("lessThanInt", 5)
260291
.max("lessThanLong", 5)
261292
.max("lessThanFloat", 5)
262293
.max("lessThanDouble", 5)
263294
.max("lessThanBigDecimal", 5)
295+
.max("lessThanScaledBigDecimal", 5)
264296
.positive("positiveInt")
265297
.positive("positiveLong")
266298
.positive("positiveFloat")
267299
.positive("positiveDouble")
268300
.positive("positiveBigDecimal")
301+
.positive("positiveScaledBigDecimal")
269302
.negative("negativeInt")
270303
.negative("negativeLong")
271304
.negative("negativeFloat")
272305
.negative("negativeDouble")
273306
.negative("negativeBigDecimal")
307+
.negative("negativeScaledBigDecimal")
274308
.between("betweenInt", -3, 5)
275309
.between("betweenLong", -3, 5)
276310
.between("betweenFloat", -3, 5)
277311
.between("betweenDouble", -3, 5)
278312
.between("betweenBigDecimal", -3, 5)
313+
.between("betweenScaledBigDecimal", -3, 5)
279314
.positiveOrZero("positiveOrZeroInt")
280315
.positiveOrZero("positiveOrZeroLong")
281316
.positiveOrZero("positiveOrZeroFloat")
282317
.positiveOrZero("positiveOrZeroDouble")
283318
.positiveOrZero("positiveOrZeroBigDecimal")
319+
.positiveOrZero("positiveOrZeroScaledBigDecimal")
284320
.negativeOrZero("negativeOrZeroInt")
285321
.negativeOrZero("negativeOrZeroLong")
286322
.negativeOrZero("negativeOrZeroFloat")
287323
.negativeOrZero("negativeOrZeroDouble")
288324
.negativeOrZero("negativeOrZeroBigDecimal")
325+
.negativeOrZero("negativeOrZeroScaledBigDecimal")
289326
.future("futureDate")
290327
.future("futureDateTime")
291328
.future("futureOffsetDateTime")
@@ -312,48 +349,55 @@ private static SomeValidParameter getSomeValidParameter() {
312349
6,
313350
6,
314351
BigDecimal.valueOf(6),
352+
ScaledBigDecimal.valueOf(6),
315353

316354
// max
317355
4,
318356
4,
319357
4,
320358
4,
321359
BigDecimal.valueOf(4),
360+
ScaledBigDecimal.valueOf(4),
322361

323362
// positive
324363
4,
325364
4,
326365
4,
327366
4,
328367
BigDecimal.valueOf(4),
368+
ScaledBigDecimal.valueOf(4),
329369

330370
// negative
331371
1,
332372
1,
333373
1,
334374
1,
335375
BigDecimal.valueOf(1),
376+
ScaledBigDecimal.valueOf(1),
336377

337378
// between
338379
-1,
339380
-1,
340381
-1,
341382
-1,
342383
BigDecimal.valueOf(-1),
384+
ScaledBigDecimal.valueOf(-1),
343385

344386
// positiveOrZero
345387
0,
346388
0,
347389
0,
348390
0,
349391
BigDecimal.valueOf(0),
392+
ScaledBigDecimal.valueOf(0),
350393

351394
// negativeOrZero
352395
0,
353396
0,
354397
0,
355398
0,
356399
BigDecimal.valueOf(0),
400+
ScaledBigDecimal.valueOf(0),
357401

358402
// future
359403
LocalDate.now().plusDays(1),

0 commit comments

Comments
 (0)