@Test public void testReloadableResourceBundleMessageSourceWithInappropriateEnglishCharset() { ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource(); ms.setBasename("org/springframework/context/support/messages"); ms.setFallbackToSystemLocale(false); Properties fileCharsets = new Properties(); fileCharsets.setProperty("org/springframework/context/support/messages", "unicode"); ms.setFileEncodings(fileCharsets); try { ms.getMessage("code1", null, Locale.ENGLISH); fail("Should have thrown NoSuchMessageException"); } catch (NoSuchMessageException ex) { // expected } }
@Test public void testReloadableResourceBundleMessageSourceWithInappropriateGermanCharset() { ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource(); ms.setBasename("org/springframework/context/support/messages"); ms.setFallbackToSystemLocale(false); Properties fileCharsets = new Properties(); fileCharsets.setProperty("org/springframework/context/support/messages_de", "unicode"); ms.setFileEncodings(fileCharsets); assertEquals("message1", ms.getMessage("code1", null, Locale.ENGLISH)); assertEquals("message2", ms.getMessage("code2", null, Locale.GERMAN)); }
@Test public void testReloadableResourceBundleMessageSourceWithInappropriateDefaultCharset() { ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource(); ms.setBasename("org/springframework/context/support/messages"); ms.setDefaultEncoding("unicode"); Properties fileCharsets = new Properties(); fileCharsets.setProperty("org/springframework/context/support/messages_de", "unicode"); ms.setFileEncodings(fileCharsets); ms.setFallbackToSystemLocale(false); try { ms.getMessage("code1", null, Locale.ENGLISH); fail("Should have thrown NoSuchMessageException"); } catch (NoSuchMessageException ex) { // expected } }