Merge pull request #27887 from dreis2211
* pr/27887: Polish "Fix tests on non English systems" Fix tests on non English systems Closes gh-27887
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.Validator;
|
import javax.validation.Validator;
|
||||||
@@ -41,8 +42,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|||||||
*/
|
*/
|
||||||
class MessageSourceMessageInterpolatorIntegrationTests {
|
class MessageSourceMessageInterpolatorIntegrationTests {
|
||||||
|
|
||||||
private final Validator validator = buildValidator();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String defaultMessage;
|
private String defaultMessage;
|
||||||
|
|
||||||
@@ -117,12 +116,15 @@ class MessageSourceMessageInterpolatorIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<String> validate(String property) {
|
private List<String> validate(String property) {
|
||||||
List<String> messages = new ArrayList<>();
|
return withEnglishLocale(() -> {
|
||||||
Set<ConstraintViolation<Object>> constraints = this.validator.validateProperty(this, property);
|
Validator validator = buildValidator();
|
||||||
for (ConstraintViolation<Object> constraint : constraints) {
|
List<String> messages = new ArrayList<>();
|
||||||
messages.add(constraint.getMessage());
|
Set<ConstraintViolation<Object>> constraints = validator.validateProperty(this, property);
|
||||||
}
|
for (ConstraintViolation<Object> constraint : constraints) {
|
||||||
return messages;
|
messages.add(constraint.getMessage());
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Validator buildValidator() {
|
private static Validator buildValidator() {
|
||||||
@@ -140,4 +142,15 @@ class MessageSourceMessageInterpolatorIntegrationTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> T withEnglishLocale(Supplier<T> supplier) {
|
||||||
|
Locale defaultLocale = Locale.getDefault();
|
||||||
|
try {
|
||||||
|
Locale.setDefault(Locale.ENGLISH);
|
||||||
|
return supplier.get();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Locale.setDefault(defaultLocale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user