Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修改原Properties读取方式,使其支持UTF-8格式,及换行符,增加测试类
- Loading branch information
凡梦星尘
committed
Sep 3, 2015
1 parent
bcc1d62
commit 635a23e
Showing
5 changed files
with
86 additions
and
4 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
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,6 @@ | ||
# 用UTF-8编辑保存配置 | ||
|
||
charset=UTF-8 | ||
longstr=Nutz \ | ||
超级棒的Framework!\ | ||
谁用谁喜欢,嘻嘻。 |
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,6 @@ | ||
# default charset store | ||
|
||
str=Nutz | ||
number=153 | ||
bool=1 | ||
chinese=\u575A\u679C |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.nutz.ioc.impl; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class PropertiesProxyTest { | ||
|
||
private PropertiesProxy pp; | ||
|
||
private static final String UTF8_CHARSET = "UTF-8"; | ||
private static final String CHINESE_STR = "Nutz 超级棒的Framework!谁用谁喜欢,嘻嘻。"; | ||
|
||
private static final String CHARSET_KEY = "charset"; | ||
private static final String LONG_STR = "longstr"; | ||
|
||
@Before | ||
public void init() { | ||
pp = new PropertiesProxy(false, "/config/conf.properties"); | ||
} | ||
|
||
@Test | ||
public void testUTF8Properties() { | ||
PropertiesProxy i18nPP = new PropertiesProxy(false, "/config/conf-utf8.properties"); | ||
i18nPP.setIgnoreResourceNotFound(true); | ||
|
||
Assert.assertEquals(UTF8_CHARSET, i18nPP.get(CHARSET_KEY)); | ||
Assert.assertEquals(CHINESE_STR, i18nPP.get(LONG_STR)); | ||
} | ||
|
||
@Test | ||
public void testString() throws UnsupportedEncodingException { | ||
Assert.assertEquals("Nutz ", pp.get("str")); | ||
Assert.assertEquals("Nutz", pp.getTrim("str")); | ||
Assert.assertEquals("坚果", new String(pp.getTrim("chinese"))); | ||
} | ||
|
||
@Test | ||
public void testNumber() { | ||
Assert.assertEquals(153, pp.getLong("number")); | ||
Assert.assertEquals(153, pp.getInt("number")); | ||
} | ||
|
||
@Test | ||
public void testBoolean() { | ||
Assert.assertEquals(true, pp.getBoolean("bool")); | ||
} | ||
|
||
@Test | ||
public void testHas() { | ||
Assert.assertTrue(pp.has("str")); | ||
} | ||
|
||
@Test | ||
public void testSize() { | ||
Assert.assertEquals(pp.getKeys().size(), 4); | ||
Assert.assertEquals(pp.getValues().size(), 4); | ||
} | ||
} |