DefaultMutableMessages extends DefaultMessages implements MutableMessages { @Override public MutableMessages setMessageTemplate(String key, String messageTemplate, Locale locale) throws IOException { Optional<ResourceBundle> b = getBundle(locale); if (!b.isPresent()) { throw new IllegalStateException("bundle not found: " + getBaseName() + " - " + locale); } MutablePropertyResourceBundle bundle = (MutablePropertyResourceBundle) b.get(); bundle.setMessageTemplate(key, messageTemplate); invalidateCachedKeysFor(locale); return this; } DefaultMutableMessages(String baseName);  DefaultMutableMessages(String baseName, Charset charset); @Override MutableMessages setMessageTemplate(String key, String messageTemplate, Locale locale);  }
@Test public void should_update_bundle() throws Exception { final File file = folder.newFile(); Files.copy(new File("src/test/resources/restx/i18n/test.properties"), file); DefaultMutableMessages m = new DefaultMutableMessages("restx.i18n.mtest") { @Override protected URL getResource(String resourceName) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } } }; assertThat(m.getMessage("key1", Locale.ENGLISH)).isEqualTo("Hello!"); m.setMessageTemplate("key1", "Greetings!", Locale.ENGLISH); assertThat(m.getMessage("key1", Locale.ENGLISH)).isEqualTo("Greetings!"); assertThat(file).hasContent("key1=Greetings!\nkey2=Hello {{who}}!"); }