-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
117 additions
and
29 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
spring.messages.basename=messages | ||
#spring.messages.basename=messages 생략도 가능함 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
hello=안녕 | ||
hello.name=안녕 {0} | ||
hello.name=안녕 {0} | ||
|
||
label.item=상품 | ||
label.item.id=상품 ID | ||
label.item.itemName=상품명 | ||
|
||
label.item.price=가격 | ||
label.item.quantity=수량 | ||
page.items=상품 목록 | ||
page.item=상품 상세 | ||
page.addItem=상품 등록 | ||
page.updateItem=상품 수정 | ||
button.save=저장 | ||
button.cancel=취소 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
hello=hello | ||
hello.name=hello {0} | ||
hello.name=hello {0} | ||
|
||
label.item=Item | ||
label.item.id=Item ID | ||
label.item.itemName=Item Name | ||
label.item.price=price | ||
label.item.quantity=quantity | ||
page.items=Item List | ||
page.item=Item Detail | ||
page.addItem=Item Add | ||
page.updateItem=Item Update | ||
button.save=Save | ||
button.cancel=Cancel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
mvc2/message/src/test/java/hello/itemservice/message/MessageSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package hello.itemservice.message; | ||
|
||
import org.assertj.core.api.AbstractStringAssert; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.NoSuchMessageException; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@SpringBootTest | ||
public class MessageSourceTest { | ||
|
||
@Autowired | ||
MessageSource ms; | ||
|
||
|
||
@Test | ||
void helloMessage() { | ||
String result = ms.getMessage("hello", null, null); | ||
assertThat(result).isEqualTo("안녕"); | ||
} | ||
|
||
@Test | ||
void notFoundMessageCode() { | ||
assertThatThrownBy(() -> ms.getMessage("no_code", null, null)) | ||
.isInstanceOf(NoSuchMessageException.class); | ||
} | ||
|
||
@Test | ||
void notFoundMessageCodeDefaultMessage() { | ||
String result = ms.getMessage("no_code", null, "기본 메시지", null); | ||
assertThat(result).isEqualTo("기본 메시지"); | ||
} | ||
|
||
@Test | ||
void argumentMessage() { | ||
String message = ms.getMessage("hello.name", new Object[]{"Spring"}, null); | ||
assertThat(message).isEqualTo("안녕 Spring"); | ||
} | ||
|
||
@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"); | ||
} | ||
|
||
} |