@Test public void shouldLocalizeEnums() throws Exception { when(localizer.localize(anyString(), anyVararg())).thenReturn("ರಘುನಂದನ"); assertThat(LocalizedMessage.messageFor(Enum.X).localize(localizer), is("ರಘುನಂದನ")); when(localizer.localize(anyString(), anyVararg())).thenReturn("ಪವನ"); assertThat(LocalizedMessage.messageFor(Enum.yyy).localize(localizer), is("ಪವನ")); }
@Test public void testMessageInEnglish() { LocalizedMessage localizedMessage = createSampleLocalizedMessage(); LocalizedMessage.setLocale(Locale.ENGLISH); assertEquals("Empty statement.", localizedMessage.getMessage()); }
@Test public void testMessageInFrench() { LocalizedMessage localizedMessage = createSampleLocalizedMessage(); LocalizedMessage.setLocale(Locale.FRENCH); assertEquals("Instruction vide.", localizedMessage.getMessage()); }
@Test public void testEnforceEnglishLanguageBySettingRootLocale() { Locale.setDefault(Locale.FRENCH); LocalizedMessage.setLocale(Locale.ROOT); LocalizedMessage localizedMessage = createSampleLocalizedMessage(); assertEquals("Empty statement.", localizedMessage.getMessage()); }
@Test public void shouldLocalizeDurations() throws Exception { Duration theDuration = new Duration(1000); String expected = "it took a long time"; when(localizer.localize(theDuration)).thenReturn(expected); assertThat(LocalizedMessage.localizeDuration(theDuration).localize(localizer), is(expected)); }
@Test public void shouldUseTheProvidedLocalizerToLocalizeWithArgs() { when(localizer.localize("ME", "for-real")).thenReturn("whateva"); assertThat( LocalizedMessage.string("me", Arrays.asList("for-real")).localize(localizer), is("whateva")); }
@Test public void shouldUseCapitalizedNoSpaceKeyToFindStringLocalization() throws Exception { when(localizer.localize(anyString(), anyVararg())).thenReturn("helped!"); String s = "Help me"; assertThat(LocalizedMessage.string(s).localize(localizer), is("helped!")); }
@Test public void shouldUseTheProvidedLocalizerToLocalize() { when(localizer.localize(anyString(), anyVararg())).thenReturn("whateva"); assertThat(LocalizedMessage.string("me").localize(localizer), is("whateva")); }
@Test public void testGetModuleId() { LocalizedMessage localizedMessage = createSampleLocalizedMessage(); assertEquals("module", localizedMessage.getModuleId()); }
@After public void tearDown() { Locale.setDefault(DEFAULT_LOCALE); LocalizedMessage.clearCache(); LocalizedMessage.setLocale(DEFAULT_LOCALE); }