Consistent test execution with Locale.UK
This commit is contained in:
parent
1db9faf248
commit
ce5869eeb0
|
@ -20,6 +20,7 @@ import java.lang.reflect.Method;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@ -29,10 +30,12 @@ import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import jakarta.validation.executable.ExecutableValidator;
|
import jakarta.validation.executable.ExecutableValidator;
|
||||||
import jakarta.validation.metadata.BeanDescriptor;
|
import jakarta.validation.metadata.BeanDescriptor;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.context.MessageSourceResolvable;
|
import org.springframework.context.MessageSourceResolvable;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
@ -92,6 +95,8 @@ class MethodValidationTests {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
|
LocaleContextHolder.setDefaultLocale(Locale.UK);
|
||||||
|
|
||||||
LocalValidatorFactoryBean validatorBean = new LocalValidatorFactoryBean();
|
LocalValidatorFactoryBean validatorBean = new LocalValidatorFactoryBean();
|
||||||
validatorBean.afterPropertiesSet();
|
validatorBean.afterPropertiesSet();
|
||||||
this.jakartaValidator = new InvocationCountingValidator(validatorBean);
|
this.jakartaValidator = new InvocationCountingValidator(validatorBean);
|
||||||
|
@ -121,6 +126,11 @@ class MethodValidationTests {
|
||||||
return handlerAdapter;
|
return handlerAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void reset() {
|
||||||
|
LocaleContextHolder.setDefaultLocale(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void modelAttribute() {
|
void modelAttribute() {
|
||||||
|
|
|
@ -22,14 +22,15 @@ import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jakarta.servlet.jsp.tagext.Tag;
|
import jakarta.servlet.jsp.tagext.Tag;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
import org.springframework.core.env.MapPropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.format.annotation.NumberFormat;
|
import org.springframework.format.annotation.NumberFormat;
|
||||||
import org.springframework.format.annotation.NumberFormat.Style;
|
import org.springframework.format.annotation.NumberFormat.Style;
|
||||||
import org.springframework.format.number.PercentStyleFormatter;
|
|
||||||
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
|
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
|
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
|
||||||
|
@ -49,6 +50,8 @@ class EvalTagTests extends AbstractTagTests {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup() {
|
||||||
|
LocaleContextHolder.setDefaultLocale(Locale.UK);
|
||||||
|
|
||||||
context = createPageContext();
|
context = createPageContext();
|
||||||
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
|
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
|
||||||
factory.afterPropertiesSet();
|
factory.afterPropertiesSet();
|
||||||
|
@ -58,6 +61,11 @@ class EvalTagTests extends AbstractTagTests {
|
||||||
tag.setPageContext(context);
|
tag.setPageContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void reset() {
|
||||||
|
LocaleContextHolder.setDefaultLocale(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void printScopedAttributeResult() throws Exception {
|
void printScopedAttributeResult() throws Exception {
|
||||||
|
@ -81,13 +89,12 @@ class EvalTagTests extends AbstractTagTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void printFormattedScopedAttributeResult() throws Exception {
|
void printFormattedScopedAttributeResult() throws Exception {
|
||||||
PercentStyleFormatter formatter = new PercentStyleFormatter();
|
|
||||||
tag.setExpression("bean.formattable");
|
tag.setExpression("bean.formattable");
|
||||||
int action = tag.doStartTag();
|
int action = tag.doStartTag();
|
||||||
assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||||
action = tag.doEndTag();
|
action = tag.doEndTag();
|
||||||
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
|
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
|
||||||
assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo(formatter.print(new BigDecimal(".25"), Locale.getDefault()));
|
assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo("25%");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue