-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for testing messageSource elements such as th-text="#{my.key}"
- Loading branch information
Adam Perry
committed
Feb 19, 2015
1 parent
d686bea
commit 161bfc2
Showing
6 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
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,9 +1,6 @@ | ||
target/ | ||
|
||
.classpath | ||
|
||
.project | ||
|
||
*.prefs | ||
|
||
thymeleaf-tdd.iml | ||
thymeleaf-tdd.iml | ||
/.idea/ |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/connect_group/thymeleaf/testing/config/TestMessageSource.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,38 @@ | ||
package com.connect_group.thymeleaf.testing.config; | ||
|
||
import org.springframework.context.support.AbstractMessageSource; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
|
||
public class TestMessageSource extends AbstractMessageSource { | ||
|
||
HashMap<String,String> messageOverrides = new HashMap<String,String>(); | ||
|
||
public void reset() { | ||
messageOverrides = new HashMap<String,String>(); | ||
} | ||
|
||
public void givenMessageWithKey(String code, String message) { | ||
messageOverrides.put(code, message); | ||
} | ||
|
||
@Override | ||
protected MessageFormat resolveCode(String key, Locale locale) { | ||
if(messageOverrides.containsKey(key)) { | ||
return new MessageFormat(messageOverrides.get(key), locale); | ||
} else { | ||
return new MessageFormat("??"+key+"_"+locale.toString()+"??", locale); | ||
} | ||
} | ||
|
||
@Override | ||
protected String resolveCodeWithoutArguments(String code, Locale locale) { | ||
if(messageOverrides.containsKey(code)) { | ||
return messageOverrides.get(code); | ||
} else { | ||
return super.resolveCodeWithoutArguments(code, locale); | ||
} | ||
} | ||
} |
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