Skip to content

Commit 9c5e608

Browse files
committed
Polish "Fix parameter replacement when message matches its code"
See gh-45212
1 parent 83901a2 commit 9c5e608

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: spring-boot-project/spring-boot/src/test/java/org/springframework/boot/validation/MessageSourceMessageInterpolatorTests.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,21 @@ void interpolateWhenParametersAreUnknownShouldLeaveThemUnchanged() {
6262
void interpolateWhenParametersAreUnknownUsingCodeAsDefaultShouldLeaveThemUnchanged() {
6363
this.messageSource.setUseCodeAsDefaultMessage(true);
6464
this.messageSource.addMessage("top", Locale.getDefault(), "{child}+{child}");
65+
assertThat(this.interpolator.interpolate("{foo}{top}{bar}", this.context))
66+
.isEqualTo("{foo}{child}+{child}{bar}");
67+
}
68+
69+
@Test
70+
void interpolateShouldReplaceParameterThatReferencesAMessageThatMatchesItsCode() {
71+
this.messageSource.addMessage("foo", Locale.getDefault(), "foo");
72+
assertThat(this.interpolator.interpolate("{foo}", this.context)).isEqualTo("foo");
73+
}
74+
75+
@Test
76+
void interpolateUsingCodeAsDefaultShouldReplaceParameterThatReferencesAMessageThatMatchesItsCode() {
77+
this.messageSource.setUseCodeAsDefaultMessage(true);
6578
this.messageSource.addMessage("foo", Locale.getDefault(), "foo");
66-
assertThat(this.interpolator.interpolate("{foo}{top}{bar}", this.context)).isEqualTo("foo{child}+{child}{bar}");
79+
assertThat(this.interpolator.interpolate("{foo}", this.context)).isEqualTo("foo");
6780
}
6881

6982
@Test

0 commit comments

Comments
 (0)