@@ -34,16 +34,16 @@ import spock.lang.Unroll
34
34
35
35
class BeanValidationFactorySpec extends Specification {
36
36
37
- BeanValidationFactory beanValidationFactory = new BeanValidationFactory ()
37
+ BeanValidationFactory beanValidationFactory = new BeanValidationFactory ()
38
38
39
39
@Unroll
40
- void "check @Valid for Object (type : #type )" () {
40
+ void "check @Valid for Object (type : #type )" () {
41
41
setup:
42
- DataType dataType = type.getDeclaredConstructor().newInstance()
42
+ DataType dataType = type.getDeclaredConstructor ().newInstance ()
43
43
44
44
when:
45
- def imports = beanValidationFactory.collectImports(dataType)
46
- def annotations = beanValidationFactory.createAnnotations(dataType)
45
+ def imports = beanValidationFactory.collectImports (dataType)
46
+ def annotations = beanValidationFactory.createAnnotations (dataType)
47
47
48
48
then:
49
49
imports == resultImports as Set<String>
@@ -62,16 +62,16 @@ class BeanValidationFactorySpec extends Specification {
62
62
}
63
63
64
64
@Unroll
65
- void "check import @Size for String (minLength : #minLength , maxLength : #maxLength , type : #type )" () {
65
+ void "check import @Size for String (minLength : #minLength , maxLength : #maxLength , type : #type )" () {
66
66
setup:
67
- DataType dataType = type.getDeclaredConstructor().newInstance()
68
- dataType.constraints = new DataTypeConstraints()
67
+ DataType dataType = type.getDeclaredConstructor ().newInstance ()
68
+ dataType.constraints = new DataTypeConstraints ()
69
69
dataType.constraints.minLength = minLength
70
70
dataType.constraints.maxLength = maxLength
71
71
72
72
when:
73
- def imports = beanValidationFactory.collectImports(dataType)
74
- def annotations = beanValidationFactory.createAnnotations(dataType)
73
+ def imports = beanValidationFactory.collectImports (dataType)
74
+ def annotations = beanValidationFactory.createAnnotations (dataType)
75
75
76
76
then:
77
77
imports == resultImports as Set<String>
@@ -80,7 +80,9 @@ class BeanValidationFactorySpec extends Specification {
80
80
where:
81
81
type | minLength | maxLength || resultImports | resultAnnotations
82
82
StringDataType | null | null || [] | " "
83
+ StringDataType | 0 | null || [] | " "
83
84
StringDataType | 1 | null || [" javax.validation.constraints.Size " ] | " @Size (min = 1 )"
85
+ StringDataType | null | 0 || [" javax.validation.constraints.Size " ] | " @Size (max = 0 )"
84
86
StringDataType | null | 2 || [" javax.validation.constraints.Size " ] | " @Size (max = 2 )"
85
87
StringDataType | 1 | 2 || [" javax.validation.constraints.Size " ] | " @Size (min = 1 , max = 2 )"
86
88
IntegerDataType | 1 | null || [] | " "
@@ -90,16 +92,16 @@ class BeanValidationFactorySpec extends Specification {
90
92
}
91
93
92
94
@Unroll
93
- void " check import @Size for Collections (minItems: #minItems, maxItems: #maxItems, type: #type)"() {
95
+ void " check import @Size for Collections (minItems: #minItems, maxItems: #maxItems, type: #type)" () {
94
96
setup :
95
- DataType dataType = type. getDeclaredConstructor(). newInstance()
96
- dataType. constraints = new DataTypeConstraints ()
97
+ DataType dataType = type. getDeclaredConstructor (). newInstance ()
98
+ dataType. constraints = new DataTypeConstraints ()
97
99
dataType. constraints. minItems = minItems
98
100
dataType. constraints. maxItems = maxItems
99
101
100
102
when :
101
- def imports = beanValidationFactory. collectImports(dataType)
102
- def annotations = beanValidationFactory. createAnnotations(dataType)
103
+ def imports = beanValidationFactory. collectImports (dataType)
104
+ def annotations = beanValidationFactory. createAnnotations (dataType)
103
105
104
106
then :
105
107
imports == resultImports as Set<String>
@@ -108,26 +110,29 @@ class BeanValidationFactorySpec extends Specification {
108
110
where :
109
111
type | minItems | maxItems || resultImports | resultAnnotations
110
112
ArrayDataType | null | null || [] | " "
113
+ ArrayDataType | 0 | null || [] | " "
111
114
ArrayDataType | 1 | null || [" javax.validation.constraints.Size" ] | " @Size(min = 1)"
115
+ ArrayDataType | null | 0 || [" javax.validation.constraints.Size" ] | " @Size(max = 0)"
112
116
ArrayDataType | null | 2 || [" javax.validation.constraints.Size" ] | " @Size(max = 2)"
113
117
ArrayDataType | 1 | 2 || [" javax.validation.constraints.Size" ] | " @Size(min = 1, max = 2)"
114
118
ListDataType | null | 2 || [" javax.validation.constraints.Size" ] | " @Size(max = 2)"
115
119
SetDataType | 1 | 2 || [" javax.validation.constraints.Size" ] | " @Size(min = 1, max = 2)"
120
+ StringDataType | 0 | null || [] | " "
116
121
StringDataType | 1 | null || [] | " "
117
122
StringDataType | null | 2 || [] | " "
118
123
LongDataType | 1 | 2 || [] | " "
119
124
}
120
125
121
126
@Unroll
122
- void " check import @NotNull (nullable: #nullable, type: #type)" () {
127
+ void " check import @NotNull (nullable: #nullable, type: #type)" () {
123
128
setup :
124
- DataType dataType = type. getDeclaredConstructor(). newInstance()
125
- dataType. constraints = new DataTypeConstraints ()
129
+ DataType dataType = type. getDeclaredConstructor (). newInstance ()
130
+ dataType. constraints = new DataTypeConstraints ()
126
131
dataType. constraints. nullable = nullable
127
132
128
133
when :
129
- def imports = beanValidationFactory. collectImports(dataType)
130
- def annotations = beanValidationFactory. createAnnotations(dataType)
134
+ def imports = beanValidationFactory. collectImports (dataType)
135
+ def annotations = beanValidationFactory. createAnnotations (dataType)
131
136
132
137
then :
133
138
imports == resultImports as Set<String >
@@ -147,16 +152,16 @@ class BeanValidationFactorySpec extends Specification {
147
152
}
148
153
149
154
@Unroll
150
- void " check import @DecimalMin (minimum: #minimum, exclusiveMinimum: #exclusiveMinimum, type: #type)" () {
155
+ void " check import @DecimalMin (minimum: #minimum, exclusiveMinimum: #exclusiveMinimum, type: #type)" () {
151
156
setup :
152
- DataType dataType = type. getDeclaredConstructor(). newInstance()
153
- dataType. constraints = new DataTypeConstraints ()
157
+ DataType dataType = type. getDeclaredConstructor (). newInstance ()
158
+ dataType. constraints = new DataTypeConstraints ()
154
159
dataType. constraints. minimum = minimum
155
160
dataType. constraints. exclusiveMinimum = exclusiveMinimum
156
161
157
162
when :
158
- def imports = beanValidationFactory. collectImports(dataType)
159
- def annotations = beanValidationFactory. createAnnotations(dataType)
163
+ def imports = beanValidationFactory. collectImports (dataType)
164
+ def annotations = beanValidationFactory. createAnnotations (dataType)
160
165
161
166
then :
162
167
imports == resultImports as Set<String >
@@ -170,6 +175,7 @@ class BeanValidationFactorySpec extends Specification {
170
175
IntegerDataType | 1 | null || [" javax.validation.constraints.DecimalMin" ] | " @DecimalMin(value = \" 1\" )"
171
176
IntegerDataType | 1 | true || [" javax.validation.constraints.DecimalMin" ] | " @DecimalMin(value = \" 1\" , inclusive = false)"
172
177
IntegerDataType | 1 | false || [" javax.validation.constraints.DecimalMin" ] | " @DecimalMin(value = \" 1\" )"
178
+ IntegerDataType | 0 | false || [" javax.validation.constraints.DecimalMin" ] | ' @DecimalMin(value = "0")'
173
179
LongDataType | null | null || [] | " "
174
180
LongDataType | null | true || [] | " "
175
181
LongDataType | null | false || [] | " "
@@ -192,16 +198,16 @@ class BeanValidationFactorySpec extends Specification {
192
198
}
193
199
194
200
@Unroll
195
- void " check import @DecimalMax (maximum: #maximum, exclusiveMaximum: #exclusiveMaximum, type: #type)" () {
201
+ void " check import @DecimalMax (maximum: #maximum, exclusiveMaximum: #exclusiveMaximum, type: #type)" () {
196
202
setup :
197
- DataType dataType = type. getDeclaredConstructor(). newInstance()
198
- dataType. constraints = new DataTypeConstraints ()
203
+ DataType dataType = type. getDeclaredConstructor (). newInstance ()
204
+ dataType. constraints = new DataTypeConstraints ()
199
205
dataType. constraints. maximum = maximum
200
206
dataType. constraints. exclusiveMaximum = exclusiveMaximum
201
207
202
208
when :
203
- def imports = beanValidationFactory. collectImports(dataType)
204
- def annotations = beanValidationFactory. createAnnotations(dataType)
209
+ def imports = beanValidationFactory. collectImports (dataType)
210
+ def annotations = beanValidationFactory. createAnnotations (dataType)
205
211
206
212
then :
207
213
imports == resultImports as Set<String >
@@ -215,6 +221,7 @@ class BeanValidationFactorySpec extends Specification {
215
221
IntegerDataType | 1 | null || [" javax.validation.constraints.DecimalMax" ] | " @DecimalMax(value = \" 1\" )"
216
222
IntegerDataType | 1 | true || [" javax.validation.constraints.DecimalMax" ] | " @DecimalMax(value = \" 1\" , inclusive = false)"
217
223
IntegerDataType | 1 | false || [" javax.validation.constraints.DecimalMax" ] | " @DecimalMax(value = \" 1\" )"
224
+ IntegerDataType | 0 | false || [" javax.validation.constraints.DecimalMax" ] | ' @DecimalMax(value = "0")'
218
225
LongDataType | null | null || [] | " "
219
226
LongDataType | null | true || [] | " "
220
227
LongDataType | null | false || [] | " "
@@ -237,18 +244,18 @@ class BeanValidationFactorySpec extends Specification {
237
244
}
238
245
239
246
@Unroll
240
- void " check import @DecimalMin and @DecimalMax (minimum: #minimum, exclusiveMinimum: #exclusiveMinimum maximum: #maximum, exclusiveMaximum: #exclusiveMaximum)" () {
247
+ void " check import @DecimalMin and @DecimalMax (minimum: #minimum, exclusiveMinimum: #exclusiveMinimum maximum: #maximum, exclusiveMaximum: #exclusiveMaximum)" () {
241
248
setup :
242
- DataType dataType = new DoubleDataType ()
243
- dataType. constraints = new DataTypeConstraints ()
249
+ DataType dataType = new DoubleDataType ()
250
+ dataType. constraints = new DataTypeConstraints ()
244
251
dataType. constraints. minimum = minimum
245
252
dataType. constraints. exclusiveMinimum = exclusiveMinimum
246
253
dataType. constraints. maximum = maximum
247
254
dataType. constraints. exclusiveMaximum = exclusiveMaximum
248
255
249
256
when :
250
- def imports = beanValidationFactory. collectImports(dataType)
251
- def annotations = beanValidationFactory. createAnnotations(dataType)
257
+ def imports = beanValidationFactory. collectImports (dataType)
258
+ def annotations = beanValidationFactory. createAnnotations (dataType)
252
259
253
260
then :
254
261
imports == resultImports as Set<String >
0 commit comments