problem-spring-web icon indicating copy to clipboard operation
problem-spring-web copied to clipboard

BindAdviceTraitTest's test failure. message is not following locale(English) setting.

Open arthur-yoon opened this issue 1 year ago • 5 comments

Description

In the BindAdviceTraitTest class, when the locale is set to English by LocaleContextHolder.setLocale(Locale.ENGLISH) in the setUp method with BeforeEach, problem.getViolations().get(*).getMessage() is output in Korean according to my locale instead of English.

Expected Behavior

problem.getViolations().get().getMessage() is "size must be between 3 and 10". problem.getViolations().get().getMessage() is "must be greater than or equal to 0".

Actual Behavior

problem.getViolations().get().getMessage() is "크기가 3에서 10 사이여야 합니다" problem.getViolations().get().getMessage() is "0 이상이어야 합니다" image

Possible Fix

Steps to Reproduce

Context

Your Environment

  • Version used: 0.29.0-SNAPSHOT
  • Link to your project: nothing changed yet. just test case failures

arthur-yoon avatar Apr 14 '23 10:04 arthur-yoon

Is spring using that locale holder for bean validation?

On Fri, 14 Apr 2023, 12:50 arthur.yoon, @.***> wrote:

Description

In the BindAdviceTraitTest class, when the locale is set to English by LocaleContextHolder.setLocale(Locale.ENGLISH) in the setUp method with BeforeEach, problem.getViolations().get(*).getMessage() is output in Korean according to my locale instead of English. Expected Behavior

problem.getViolations().get( ).getMessage() is "size must be between 3 and 10". problem.getViolations().get().getMessage() is "must be greater than or equal to 0". Actual Behavior

problem.getViolations().get( ).getMessage() is "크기가 3에서 10 사이여야 합니다" problem.getViolations().get().getMessage() is "0 이상이어야 합니다" [image: image] https://user-images.githubusercontent.com/47406496/232022814-82e3b277-4f5c-4e96-ab90-7a6f71e803a3.png Possible Fix Steps to Reproduce

Context Your Environment

  • Version used: 0.29.0-SNAPSHOT
  • Link to your project: nothing changed yet. just test case failures

— Reply to this email directly, view it on GitHub https://github.com/zalando/problem-spring-web/issues/905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADI7HK5IW2KDTBEFLPVTS3XBETWDANCNFSM6AAAAAAW6IJZNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

whiskeysierra avatar Apr 14 '23 13:04 whiskeysierra

I at least experience the same with my laptop being set to German, so I also get issues with the test execution.

cberg-zalando avatar Apr 14 '23 13:04 cberg-zalando

LocaleContextHolder.setLocale(Locale.ENGLISH

it's not enough to call LocaleContextHolder.setLocale(Locale.ENGLISH), which sets the Locale information used by Spring. LocaleContextHolder.setLocale(Locale.ENGLISH) sets the locale to English for the just current thread. However, the error messages used by Bean Validation are obtained from Spring's MessageSource, which by default uses the operating system's default locale.

arthur-yoon avatar Apr 17 '23 01:04 arthur-yoon

I at least experience the same with my laptop being set to German, so I also get issues with the test execution.

It's correct to use English as the message source instead of changing the locale setting, but I don't think this is a good idea, because if the message.properties are changed, the test case will eventually break. Shouldn't we modify it to something other than testing if the sentences match?

arthur-yoon avatar Apr 17 '23 01:04 arthur-yoon

is this issue handled?

arthur-yoon avatar Jul 19 '23 06:07 arthur-yoon