Polish "Fix parameter replacement when message matches its code"

See gh-45212
This commit is contained in:
Andy Wilkinson 2025-04-16 14:44:45 +01:00
parent 83901a22b6
commit 9c5e608f50
1 changed files with 14 additions and 1 deletions

View File

@ -62,8 +62,21 @@ class MessageSourceMessageInterpolatorTests {
void interpolateWhenParametersAreUnknownUsingCodeAsDefaultShouldLeaveThemUnchanged() {
this.messageSource.setUseCodeAsDefaultMessage(true);
this.messageSource.addMessage("top", Locale.getDefault(), "{child}+{child}");
assertThat(this.interpolator.interpolate("{foo}{top}{bar}", this.context))
.isEqualTo("{foo}{child}+{child}{bar}");
}
@Test
void interpolateShouldReplaceParameterThatReferencesAMessageThatMatchesItsCode() {
this.messageSource.addMessage("foo", Locale.getDefault(), "foo");
assertThat(this.interpolator.interpolate("{foo}{top}{bar}", this.context)).isEqualTo("foo{child}+{child}{bar}");
assertThat(this.interpolator.interpolate("{foo}", this.context)).isEqualTo("foo");
}
@Test
void interpolateUsingCodeAsDefaultShouldReplaceParameterThatReferencesAMessageThatMatchesItsCode() {
this.messageSource.setUseCodeAsDefaultMessage(true);
this.messageSource.addMessage("foo", Locale.getDefault(), "foo");
assertThat(this.interpolator.interpolate("{foo}", this.context)).isEqualTo("foo");
}
@Test