Skip to content

Commit e16c322

Browse files
author
handyande
committed
Update test code to be more certain our outcome is correct
Give all the bundles a prefix, not just some - now we are certain we got the right response PLX-257 - Add some properties test to demonstrate the correct usage under a non-english locale
1 parent 964702b commit e16c322

File tree

7 files changed

+50
-18
lines changed

7 files changed

+50
-18
lines changed

src/test/java/org/codehaus/plexus/i18n/BarBundle.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public class BarBundle
1010
{
1111
private static final Object[][] CONTENTS =
1212
{
13-
{ "key1", "value1" },
14-
{ "key2", "value2" },
15-
{ "key3", "value3" },
16-
{ "key4", "value4" }
13+
{ "key1", "[] value1" },
14+
{ "key2", "[] value2" },
15+
{ "key3", "[] value3" },
16+
{ "key4", "[] value4" }
1717
};
1818

1919
protected Object[][] getContents()

src/test/java/org/codehaus/plexus/i18n/BarBundle_en_US.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public class BarBundle_en_US
1010
{
1111
private static final Object[][] CONTENTS =
1212
{
13-
{ "key1", "value1" },
14-
{ "key2", "value2" },
15-
{ "key3", "value3" },
16-
{ "key4", "value4" }
13+
{ "key1", "[en_US] value1" },
14+
{ "key2", "[en_US] value2" },
15+
{ "key3", "[en_US] value3" },
16+
{ "key4", "[en_US] value4" }
1717
};
1818

1919
protected Object[][] getContents()

src/test/java/org/codehaus/plexus/i18n/DefaultI18NTest.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,47 @@ public void testLocalization()
8383
{
8484
String s0 = i18n.getString( null, null, "key1" );
8585

86-
assertEquals( "Unable to retrieve localized text for locale: default", s0, "value1" );
86+
assertEquals( "Unable to retrieve localized text for locale: default", s0, "[] value1" );
8787

8888
String s1 = i18n.getString( null, new Locale( "en", "US" ), "key2" );
8989

90-
assertEquals( "Unable to retrieve localized text for locale: en-US", s1, "value2" );
90+
assertEquals( "Unable to retrieve localized text for locale: en-US", s1, "[en_US] value2" );
9191

9292
String s2 = i18n.getString( "org.codehaus.plexus.i18n.BarBundle", new Locale( "ko", "KR" ), "key3" );
9393

9494
assertEquals( "Unable to retrieve localized text for locale: ko-KR", s2, "[ko] value3" );
9595

96+
String s3 = i18n.getString( "org.codehaus.plexus.i18n.BarBundle", new Locale( "ja" ), "key1" );
97+
98+
assertEquals( "Unable to fall back from non-existant locale: jp", "[] value1", s3 );
99+
96100
String s4 = i18n.getString( "org.codehaus.plexus.i18n.FooBundle", new Locale( "fr" ), "key3" );
97101

98-
assertEquals( "Unable to retrieve localized text for locale: fr-US", s4, "[fr] value3" );
102+
assertEquals( "Unable to retrieve localized text for locale: fr", s4, "[fr] value3" );
103+
104+
String s5 = i18n.getString( "org.codehaus.plexus.i18n.FooBundle", new Locale( "fr", "FR" ), "key3" );
105+
106+
assertEquals( "Unable to retrieve localized text for locale: fr-FR", s5, "[fr] value3" );
107+
108+
String s6 = i18n.getString( "org.codehaus.plexus.i18n.i18n", null, "key1" );
109+
110+
assertEquals( "Unable to retrieve localized properties for locale: default", "[] value1", s6 );
111+
112+
Locale old = Locale.getDefault();
113+
Locale.setDefault(Locale.FRENCH);
114+
try
115+
{
116+
String s7 = i18n.getString( "org.codehaus.plexus.i18n.i18n", Locale.ENGLISH, "key1" );
117+
118+
assertEquals( "Not picking up new default locale: fr", "[fr] value1", s7 );
119+
120+
String s8 = i18n.getString( "org.codehaus.plexus.i18n.i18n", Locale.ITALIAN, "key1" );
99121

100-
String s5 = i18n.getString( "org.codehaus.plexus.i18n.i18n", null, "key1" );
122+
assertEquals( "Unable to retrieve localized properties for locale: it", "[it] value1", s8 );
101123

102-
assertEquals( "value1", s5 );
124+
} finally {
125+
Locale.setDefault(old);
126+
}
103127
}
104128

105129
public void testLocalizedMessagesWithFormatting()

src/test/java/org/codehaus/plexus/i18n/FooBundle_en.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class FooBundle_en extends ListResourceBundle
99
{
1010
private static final Object[][] CONTENTS =
1111
{
12-
{ "key1", "value1" },
13-
{ "key2", "value2" },
14-
{ "key3", "value3" },
15-
{ "key4", "value4" }
12+
{ "key1", "[en] value1" },
13+
{ "key2", "[en] value2" },
14+
{ "key3", "[en] value3" },
15+
{ "key4", "[en] value4" }
1616
};
1717

1818
protected Object[][] getContents()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
key1 = value1
1+
key1 = [] value1
22
thanks.message = Thanks {0}!
33
thanks.message1 = Thanks {0} {1}!
44
thanks.message2 = Thanks {0} {1}!
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
key1 = [fr] value1
2+
thanks.message = Merci {0}!
3+
thanks.message1 = Merci {0} {1}!
4+
thanks.message2 = Merci {0} {1}!
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
key1 = [it] value1
2+
thanks.message = Grazie {0}!
3+
thanks.message1 = Grazie {0} {1}!
4+
thanks.message2 = Grazie {0} {1}!

0 commit comments

Comments
 (0)