๐ย Spring Message Source ์ค์
โ ๏ธย ํ๊ธ ๊นจ์ง ํ์ ํด๊ฒฐ๋ฐฉ๋ฒ
MessageSource
๋ฅผ ์ฌ์ฉํด ๋ฑ๋กํ ๋ฉ์์ง๋ฅผ ํ์ธํ ์ ์๋ค.@SpringBootTest
public class MessageSourceTest {
@Autowired
MessageSource ms;
@Test
void helloMessage() {
String result = ms.getMessage("hello", null, null);
assertThat(result).isEqualTo("์๋
");
}
NoSuchMessageException
์ด ๋ฐ์๋๋ค.@Test
void notFoundMessageCode() {
assertThatThrownBy(() -> ms.getMessage("no_code", null, null))
.isInstanceOf(NoSuchMessageException.class);
}
@Test
void defaultMessageCode() {
String result = ms.getMessage("no_code", null, "๊ธฐ๋ณธ ๋ฉ์์ง", null);
assertThat(result).isEqualTo("๊ธฐ๋ณธ ๋ฉ์์ง");
}
@Test
void argumentMessage() {
String result = ms.getMessage("hello.name", new Object[]{"Spring"}, null);
assertThat(result).isEqualTo("์๋
Spring");
}
null
Locale.KOREA
Locale.ENGLISH
@Test
void defaultLang() {
assertThat(ms.getMessage("hello", null, null))
.isEqualTo("์๋
");
assertThat(ms.getMessage("hello", null, Locale.KOREA))
.isEqualTo("์๋
");
}
@Test
void enLang() {
assertThat(ms.getMessage("hello", null, Locale.ENGLISH))
.isEqualTo("hello");
}