C10NMessage { public String get() { return currentLocaleMessage; } C10NMessage(Locale currentLocale, String currentLocaleMessage, Map<Locale, String> messages); String get(); String get(Locale locale); Locale getCurrentLocale(); Map<Locale, String> asMap();  }
@Test public void messagesForEachLocaleAreContained() throws Exception { MyMsg myMsg = C10N.get(MyMsg.class); assertThat(myMsg.myMsg().get(), is("english")); assertThat(myMsg.myMsg().get(Locale.ENGLISH), is("english")); assertThat(myMsg.myMsg().get(Locale.JAPANESE), is("japanese")); assertThat(myMsg.myMsg().get(Locale.FRENCH), nullValue()); assertThat(myMsg.myMsgWithArg(123).get(), is("english 123")); assertThat(myMsg.myMsgWithArg(123).get(Locale.ENGLISH), is("english 123")); assertThat(myMsg.myMsgWithArg(123).get(Locale.JAPANESE), is("japanese 123")); assertThat(myMsg.myMsgWithArg(123).get(Locale.FRENCH), nullValue()); }
@Test public void defaultMessageFallsBackWhenNoMatchingLocaleIsPresent() throws Exception { MyMsg myMsg = C10N.get(MyMsg.class); Locale.setDefault(Locale.CHINESE); assertThat(myMsg.myMsg().get(), is("fallback")); assertThat(myMsg.myMsg().get(Locale.ENGLISH), is("english")); assertThat(myMsg.myMsg().get(Locale.JAPANESE), is("japanese")); assertThat(myMsg.myMsg().get(Locale.FRENCH), nullValue()); assertThat(myMsg.myMsgWithArg(123).get(), is("fallback 123")); assertThat(myMsg.myMsgWithArg(123).get(Locale.ENGLISH), is("english 123")); assertThat(myMsg.myMsgWithArg(123).get(Locale.JAPANESE), is("japanese 123")); assertThat(myMsg.myMsgWithArg(123).get(Locale.FRENCH), nullValue()); }