#1467 Fix error in placeholder migration, create and fix tests

This commit is contained in:
ljacqu
2018-01-29 22:15:39 +01:00
parent 760a2a909c
commit abd19cdb86
8 changed files with 193 additions and 37 deletions
@@ -180,7 +180,7 @@ public class MessagesIntegrationTest {
messages.send(sender, key);
// then
verify(sender).sendMessage("Use /captcha THE_CAPTCHA to solve the captcha");
verify(sender).sendMessage("Use /captcha %captcha_code to solve the captcha");
}
@Test
@@ -5,6 +5,7 @@ import fr.xephi.authme.command.help.HelpSection;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
@@ -33,6 +34,7 @@ public class YamlTextFileCheckerTest {
}
@Test
@Ignore // TODO #1467: Migrate all files to new keys
public void testAllMessagesYmlFiles() {
checkFiles(
Pattern.compile("messages_\\w+\\.yml"),
@@ -67,5 +67,29 @@ public class MessageUpdaterTest {
assertThat(configuration.getString(MessageKey.ERROR.getKey()), equalTo("&4An unexpected error occurred, please contact an administrator!"));
}
// TODO #1467: Check migration of old keys
@Test
public void shouldMigrateOldEntries() throws IOException {
// given
File messagesFile = temporaryFolder.newFile();
Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "message/messages_en_old.yml"), messagesFile);
// when
boolean wasChanged = messageUpdater.migrateAndSave(messagesFile, "messages/messages_en.yml", "messages/messages_en.yml");
// then
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"));
}
}