有2个类:
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" }
};
}
}
当尝试获取 locale en的包时,它总是获取de的包,而不是默认的包 ( 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
这是正确的行为还是我误解了什么?