#450 Make reload & messages functionality use NewSetting

- Change ReloadCommand to use the new setting functionality
- Check and construct the messages file in NewSetting
- Unrelated: change MessagesManager not to extend CustomConfiguration anymore
This commit is contained in:
ljacqu
2016-01-31 09:55:02 +01:00
parent 059175f14e
commit e747dfeb7f
11 changed files with 185 additions and 123 deletions
@@ -18,6 +18,7 @@ import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import java.io.File;
import java.util.Arrays;
import java.util.List;
@@ -95,19 +96,6 @@ public class CommandServiceTest {
verify(commandMapper).mapPartsToCommand(sender, commandParts);
}
@Test
@Ignore
public void shouldRunTaskInAsync() {
// given
Runnable runnable = mock(Runnable.class);
// when
commandService.runTaskAsynchronously(runnable);
// then
// TODO ljacqu 20151226: AuthMe#getServer() is final, i.e. not mockable
}
@Test
public void shouldGetDataSource() {
// given
@@ -193,10 +181,40 @@ public class CommandServiceTest {
given(settings.getProperty(property)).willReturn(7);
// when
int result = settings.getProperty(property);
int result = commandService.getProperty(property);
// then
assertThat(result, equalTo(7));
verify(settings).getProperty(property);
}
@Test
public void shouldReloadMessages() {
// given
File file = new File("some/bogus-file.test");
// when
commandService.reloadMessages(file);
// then
verify(messages).reload(file);
}
@Test
public void shouldReturnSettings() {
// given/when
NewSetting result = commandService.getSettings();
// then
assertThat(result, equalTo(settings));
}
@Test
public void shouldReturnAuthMe() {
// given/when
AuthMe result = commandService.getAuthMe();
// then
assertThat(result, equalTo(authMe));
}
}
@@ -1,6 +1,5 @@
package fr.xephi.authme.output;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.WrapperMock;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -37,15 +36,12 @@ public class MessagesIntegrationTest {
public void setUpMessages() {
WrapperMock.createInstance();
Settings.messagesLanguage = "en";
URL url = getClass().getClassLoader().getResource(YML_TEST_FILE);
if (url == null) {
throw new RuntimeException("File '" + YML_TEST_FILE + "' could not be loaded");
}
Settings.messageFile = new File(url.getFile());
Settings.messagesLanguage = "en";
messages = Messages.getInstance();
messages = new Messages(new File(url.getFile()));
}
@Test
@@ -2,6 +2,7 @@ package fr.xephi.authme.settings;
import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.TestConfiguration;
import fr.xephi.authme.settings.propertymap.PropertyMap;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
@@ -40,7 +41,7 @@ public class NewSettingTest {
setReturnValue(file, TestConfiguration.SYSTEM_NAME, "myTestSys");
// when / then
NewSetting settings = new NewSetting(file, new File("conf.txt"), null);
NewSetting settings = new NewSetting(file, new File("conf.txt"), (PropertyMap) null);
assertThat(settings.getProperty(TestConfiguration.VERSION_NUMBER), equalTo(20));
assertThat(settings.getProperty(TestConfiguration.SKIP_BORING_FEATURES), equalTo(true));
@@ -2,6 +2,7 @@ package fr.xephi.authme.util;
import org.junit.Test;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.List;
@@ -135,4 +136,13 @@ public class StringUtilsTest {
assertThat(StringUtils.getDifference("test", "bear"), equalTo(0.75));
assertThat(StringUtils.getDifference("test", "something"), greaterThan(0.88));
}
@Test
public void shouldConstructPath() {
// given/when
String result = StringUtils.makePath("path", "to", "test-file.txt");
// then
assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt"));
}
}