### Question:
MessageUpdater { public boolean migrateAndSave(File userFile, String localJarPath, String defaultJarPath) { JarMessageSource jarMessageSource = new JarMessageSource(localJarPath, defaultJarPath); return migrateAndSave(userFile, jarMessageSource); }  static ConfigurationData getConfigurationData(); boolean migrateAndSave(File userFile, String localJarPath, String defaultJarPath);  }### Answer:
@Test public void shouldNotUpdateDefaultFile() throws IOException { String messagesFilePath = "messages/messages_en.yml"; File messagesFile = temporaryFolder.newFile(); Files.copy(TestHelper.getJarFile("/" + messagesFilePath), messagesFile); long modifiedDate = messagesFile.lastModified(); boolean wasChanged = messageUpdater.migrateAndSave(messagesFile, messagesFilePath, messagesFilePath); assertThat(wasChanged, equalTo(false)); assertThat(messagesFile.lastModified(), equalTo(modifiedDate)); }
@Test public void shouldAddMissingKeys() throws IOException { File messagesFile = temporaryFolder.newFile(); Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "message/messages_test.yml"), messagesFile); boolean wasChanged = messageUpdater.migrateAndSave(messagesFile, "does-not-exist", "messages/messages_en.yml"); assertThat(wasChanged, equalTo(true)); FileConfiguration configuration = YamlConfiguration.loadConfiguration(messagesFile); assertThat(configuration.getString(MessageKey.LOGIN_SUCCESS.getKey()), equalTo("&cHere we have&bdefined some colors &dand some other &lthings")); assertThat(configuration.getString(MessageKey.EMAIL_ALREADY_USED_ERROR.getKey()), equalTo("")); assertThat(configuration.getString(MessageKey.SECOND.getKey()), equalTo("second")); assertThat(configuration.getString(MessageKey.ERROR.getKey()), equalTo("&4An unexpected error occurred, please contact an administrator!")); }
@Test public void shouldMigrateOldEntries() throws IOException { File messagesFile = temporaryFolder.newFile(); Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "message/messages_en_old.yml"), messagesFile); boolean wasChanged = messageUpdater.migrateAndSave(messagesFile, "messages/messages_en.yml", "messages/messages_en.yml"); assertThat(wasChanged, equalTo(true)); FileConfiguration configuration = YamlConfiguration.loadConfiguration(messagesFile); assertThat(configuration.getString(MessageKey.PASSWORD_MATCH_ERROR.getKey()), equalTo("Password error message")); assertThat(configuration.getString(MessageKey.INVALID_NAME_CHARACTERS.getKey()), equalTo("not valid username: Allowed chars are %valid_chars")); assertThat(configuration.getString(MessageKey.INVALID_OLD_EMAIL.getKey()), equalTo("Email (old) is not valid!!")); assertThat(configuration.getString(MessageKey.CAPTCHA_WRONG_ERROR.getKey()), equalTo("The captcha code is %captcha_code for you")); assertThat(configuration.getString(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED.getKey()), equalTo("Now type /captcha %captcha_code")); assertThat(configuration.getString(MessageKey.SECONDS.getKey()), equalTo("seconds in plural")); }