0
有2類:資源包越來越錯了ListResourceBundle(按區域)
public class MyListResourceBundle_de extends ListResourceBundle {
@Override
protected Object[][] getContents() {
return new Object[][] {
{ "hello", "Hallo" }, { "world", "Welt" }
};
}
}
public class MyListResourceBundle extends ListResourceBundle {
@Override
protected Object[][] getContents() {
return new Object[][] {
{ "hello", "Hello" }, { "world", "World" }
};
}
}
當試圖獲得區域捆帶它總是得到一個德不是默認的一個(MyListResourceBundle
) :
public class MyTest {
private static ResourceBundle bundle;
@BeforeClass
public static void setup() {
bundle = ResourceBundle.getBundle("test.MyListResourceBundle", new Locale("en"));
}
@Test
public void testLocale() {
for (String key : bundle.keySet()) {
System.out.println(key + " -> " + bundle.getString(key));
}
assertEquals("en", bundle.getLocale().toString());
}
}
的輸出是下面的:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running test.MyTest
hello -> Hallo
world -> Welt
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.067 sec <<< FAILURE!
Results :
Failed tests: testLocale(test.MyTest): expected:<[en]> but was:<[de]>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
這是正確的行爲還是我誤解了某些東西?
沒有,同樣的結果。如果沒有'MyListResourceBundle_en',它應該使用'MyListResourceBundle'來代替。但即使我指定'en'作爲區域設置,它總是使用'MyListResourceBundle_de'。 – dtrunk