9
9
import static org .hibernate .validator .testutil .ConstraintViolationAssert .assertThat ;
10
10
import static org .hibernate .validator .testutil .ConstraintViolationAssert .violationOf ;
11
11
12
+ import java .time .Duration ;
12
13
import java .util .Locale ;
13
14
import java .util .Set ;
14
15
20
21
import jakarta .validation .constraints .Email ;
21
22
22
23
import org .hibernate .validator .constraints .Range ;
24
+ import org .hibernate .validator .constraints .time .DurationMax ;
25
+ import org .hibernate .validator .constraints .time .DurationMin ;
23
26
import org .hibernate .validator .messageinterpolation .ResourceBundleMessageInterpolator ;
24
27
import org .hibernate .validator .testutil .TestForIssue ;
25
28
import org .hibernate .validator .testutils .ValidatorUtil ;
@@ -132,6 +135,40 @@ public void testConditionalDecimalMinMessageDependingOnInclusiveFlag() {
132
135
);
133
136
}
134
137
138
+ @ Test
139
+ @ TestForIssue (jiraKey = "HV-1943" )
140
+ public void testConditionalDecimalMinMaxMessagesForFrenchLocale () {
141
+ Configuration <?> config = ValidatorUtil .getConfiguration ( Locale .FRENCH );
142
+ config .messageInterpolator ( new ResourceBundleMessageInterpolator () );
143
+ Validator validator = config .buildValidatorFactory ().getValidator ();
144
+
145
+
146
+ Set <ConstraintViolation <DoubleHolder >> constraintViolations = validator .validate ( new DoubleHolder () );
147
+ assertThat ( constraintViolations ).containsOnlyViolations (
148
+ violationOf ( DecimalMin .class ).withMessage ( "doit être supérieur ou égal à 1.0" ),
149
+ violationOf ( DecimalMin .class ).withMessage ( "doit être supérieur à 1.0" ),
150
+ violationOf ( DecimalMax .class ).withMessage ( "doit être inférieur ou égal à 1.0" ),
151
+ violationOf ( DecimalMax .class ).withMessage ( "doit être inférieur à 1.0" )
152
+ );
153
+ }
154
+
155
+ @ Test
156
+ @ TestForIssue (jiraKey = "HV-1943" )
157
+ public void testConditionalDurationMinMaxMessagesForFrenchLocale () {
158
+ Configuration <?> config = ValidatorUtil .getConfiguration ( Locale .FRENCH );
159
+ config .messageInterpolator ( new ResourceBundleMessageInterpolator () );
160
+ Validator validator = config .buildValidatorFactory ().getValidator ();
161
+
162
+
163
+ Set <ConstraintViolation <DurationHolder >> constraintViolations = validator .validate ( new DurationHolder () );
164
+ assertThat ( constraintViolations ).containsOnlyViolations (
165
+ violationOf ( DurationMin .class ).withMessage ( "doit être plus long ou égal à 2 jours" ),
166
+ violationOf ( DurationMin .class ).withMessage ( "doit être plus long que 2 jours" ),
167
+ violationOf ( DurationMax .class ).withMessage ( "doit être plus court ou égal à 2 jours" ),
168
+ violationOf ( DurationMax .class ).withMessage ( "doit être plus court que 2 jours" )
169
+ );
170
+ }
171
+
135
172
private static class DoubleHolder {
136
173
@ DecimalMax (value = "1.0" )
137
174
private final double inclusiveMaxDouble ;
@@ -152,6 +189,26 @@ private DoubleHolder() {
152
189
}
153
190
}
154
191
192
+ private static class DurationHolder {
193
+ @ DurationMax (days = 2L )
194
+ private final Duration inclusiveMaxDuration ;
195
+ @ DurationMax (days = 2L , inclusive = false )
196
+ private final Duration exclusiveMaxDuration ;
197
+
198
+ @ DurationMin (days = 2L )
199
+ private final Duration inclusiveMinDuration ;
200
+ @ DurationMin (days = 2L , inclusive = false )
201
+ private final Duration exclusiveMinDuration ;
202
+
203
+ private DurationHolder () {
204
+ this .inclusiveMaxDuration = Duration .ofDays ( 3 );
205
+ this .exclusiveMaxDuration = Duration .ofDays ( 2 );
206
+
207
+ this .inclusiveMinDuration = Duration .ofDays ( 1 );
208
+ this .exclusiveMinDuration = Duration .ofDays ( 2 );
209
+ }
210
+ }
211
+
155
212
/**
156
213
* A message interpolator that enforces one given locale to be used for message
157
214
* interpolation.
0 commit comments