### Question:
CommandMigrationService implements MigrationService { @Override public boolean checkAndMigrate(PropertyResource resource, List<Property<?>> properties) { final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.getValue(resource); if (moveOtherAccountsConfig(commandConfig) || isFileEmpty(resource)) { resource.setValue("", commandConfig); return true; } return false; } CommandMigrationService(); @Override boolean checkAndMigrate(PropertyResource resource, List<Property<?>> properties);  }### Answer:
@Test public void shouldRewriteForEmptyFile() { File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.empty.yml"); PropertyResource resource = new YamlFileResource(commandFile); boolean result = commandMigrationService.checkAndMigrate( resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); assertThat(result, equalTo(true)); }
@Test public void shouldRewriteIncompleteFile() { File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.incomplete.yml"); PropertyResource resource = new YamlFileResource(commandFile); boolean result = commandMigrationService.checkAndMigrate( resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); assertThat(result, equalTo(true)); }
@Test public void shouldNotChangeCompleteFile() { File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.complete.yml"); PropertyResource resource = new YamlFileResource(commandFile); boolean result = commandMigrationService.checkAndMigrate( resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); assertThat(result, equalTo(false)); }
@Test public void shouldMigrateOldOtherAccountsCommand() { given(settingsMigrationService.hasOldOtherAccountsCommand()).willReturn(true); given(settingsMigrationService.getOldOtherAccountsCommand()) .willReturn("helpop %playername% (%playerip%) has other accounts!"); given(settingsMigrationService.getOldOtherAccountsCommandThreshold()).willReturn(3); File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.complete.yml"); PropertyResource resource = new YamlFileResource(commandFile); commandMigrationService.checkAndMigrate( resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); Map<String, OnLoginCommand> onLoginCommands = CommandSettingsHolder.COMMANDS.getValue(resource).getOnLogin(); assertThat(onLoginCommands, aMapWithSize(6)); OnLoginCommand newCommand = getUnknownOnLoginCommand(onLoginCommands); assertThat(newCommand.getCommand(), equalTo("helpop %p (%ip) has other accounts!")); assertThat(newCommand.getExecutor(), equalTo(Executor.CONSOLE)); assertThat(newCommand.getIfNumberOfAccountsAtLeast().get(), equalTo(3)); assertThat(newCommand.getIfNumberOfAccountsLessThan().isPresent(), equalTo(false)); }