1
2
3
4
5
6
7
8
9 package tsukuba_bunko.resource.test;
10
11 import java.net.URL;
12 import java.text.MessageFormat;
13
14 import junit.framework.TestCase;
15
16 import tsukuba_bunko.resource.Resources;
17
18
19 /***
20 * {@link tsukuba_bunko.resource.MessageFormatDeserializer} をテストする TestCase です。
21 * @author $Author: ppoi $
22 * @version $Revision: 1.1 $
23 */
24 public class MessageFormatDeserializerTestCase extends TestCase {
25
26 /***
27 * <code>MessageFormatDeserializerTestCase</code> のインスタンスを生成します。
28 */
29 public MessageFormatDeserializerTestCase( String name )
30 {
31 super( name );
32 }
33
34
35 public void testLoad()
36 throws Exception
37 {
38 URL resourceURL = getClass().getResource( "test-messageformat.xml" );
39 assertNotNull( "resource file not found", resourceURL );
40
41
42 Resources resources = Resources.newInstance( resourceURL );
43
44 MessageFormat value = (MessageFormat)resources.getResource( "tbas.libtbas.resource-manager.test.item1" );
45 assertNotNull( "item1", value );
46 Object[] params = { "1", "2" };
47 String pattern = "testmessage {0} {1}";
48 assertEquals( "item1-pattern", pattern, value.toPattern() );
49 assertEquals( "item1-message", "testmessage 1 2", value.format(params) );
50 assertEquals( "item1-format", MessageFormat.format(pattern, params), value.format(params) );
51
52 Integer intValue = (Integer)resources.getResource( "tbas.libtbas.resource-manager.hoge" );
53 assertNotNull( "hoge", intValue );
54 assertEquals( "hoge", intValue, new Integer(3) );
55 }
56 }