#347 Add NewSetting to command service
- Adjust NewSetting constructor to match needs in AuthMe - Add NewSetting to the command service - See CaptchaCommand for a sample replacement from Settings to NewSetting
This commit is contained in:
@@ -8,6 +8,9 @@ import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.custom.NewSetting;
|
||||
import fr.xephi.authme.settings.custom.SecuritySettings;
|
||||
import fr.xephi.authme.settings.domain.Property;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
@@ -36,6 +39,7 @@ public class CommandServiceTest {
|
||||
private Messages messages;
|
||||
private PasswordSecurity passwordSecurity;
|
||||
private CommandService commandService;
|
||||
private NewSetting settings;
|
||||
|
||||
@Before
|
||||
public void setUpService() {
|
||||
@@ -44,7 +48,8 @@ public class CommandServiceTest {
|
||||
helpProvider = mock(HelpProvider.class);
|
||||
messages = mock(Messages.class);
|
||||
passwordSecurity = mock(PasswordSecurity.class);
|
||||
commandService = new CommandService(authMe, commandMapper, helpProvider, messages, passwordSecurity);
|
||||
settings = mock(NewSetting.class);
|
||||
commandService = new CommandService(authMe, commandMapper, helpProvider, messages, passwordSecurity, settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,4 +200,18 @@ public class CommandServiceTest {
|
||||
assertThat(result, equalTo(givenMessages));
|
||||
verify(messages).retrieve(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveProperty() {
|
||||
// given
|
||||
Property<Integer> property = SecuritySettings.CAPTCHA_LENGTH;
|
||||
given(settings.getProperty(property)).willReturn(7);
|
||||
|
||||
// when
|
||||
int result = settings.getProperty(property);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(7));
|
||||
verify(settings).getProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.custom.SecuritySettings;
|
||||
import fr.xephi.authme.util.WrapperMock;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -20,6 +20,7 @@ import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -35,8 +36,8 @@ public class CaptchaCommandTest {
|
||||
@Before
|
||||
public void setUpWrapperMock() {
|
||||
wrapperMock = WrapperMock.createInstance();
|
||||
Settings.useCaptcha = true;
|
||||
commandService = mock(CommandService.class);
|
||||
given(commandService.getProperty(SecuritySettings.USE_CAPTCHA)).willReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +47,7 @@ public class CaptchaCommandTest {
|
||||
ExecutableCommand command = new CaptchaCommand();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), mock(CommandService.class));
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
|
||||
// then
|
||||
assertThat(wrapperMock.wasMockCalled(AuthMe.class), equalTo(false));
|
||||
@@ -54,14 +55,14 @@ public class CaptchaCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void shouldRejectIfCaptchaIsNotUsed() {
|
||||
// given
|
||||
Player player = mockPlayerWithName("testplayer");
|
||||
ExecutableCommand command = new CaptchaCommand();
|
||||
given(commandService.getProperty(SecuritySettings.USE_CAPTCHA)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("1234"), mock(CommandService.class));
|
||||
command.executeCommand(player, Collections.singletonList("1234"), commandService);
|
||||
|
||||
// then
|
||||
verify(commandService).send(player, MessageKey.USAGE_LOGIN);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class NewSettingIntegrationTest {
|
||||
.build();
|
||||
for (Map.Entry<Property<?>, Object> entry : expectedValues.entrySet()) {
|
||||
assertThat("Property '" + entry.getKey().getPath() + "' has expected value",
|
||||
settings.getOption(entry.getKey()), equalTo(entry.getValue()));
|
||||
settings.getProperty(entry.getKey()), equalTo(entry.getValue()));
|
||||
}
|
||||
assertThat(file.exists(), equalTo(false));
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class NewSettingIntegrationTest {
|
||||
.build();
|
||||
for (Map.Entry<Property<?>, Object> entry : expectedValues.entrySet()) {
|
||||
assertThat("Property '" + entry.getKey().getPath() + "' has expected value",
|
||||
settings.getOption(entry.getKey()), equalTo(entry.getValue()));
|
||||
settings.getProperty(entry.getKey()), equalTo(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ public class NewSettingTest {
|
||||
// when / then
|
||||
NewSetting settings = new NewSetting(file, new File("conf.txt"), null);
|
||||
|
||||
assertThat(settings.getOption(TestConfiguration.VERSION_NUMBER), equalTo(20));
|
||||
assertThat(settings.getOption(TestConfiguration.SKIP_BORING_FEATURES), equalTo(true));
|
||||
assertThat(settings.getOption(TestConfiguration.RATIO_LIMIT), equalTo(4.25));
|
||||
assertThat(settings.getOption(TestConfiguration.SYSTEM_NAME), equalTo("myTestSys"));
|
||||
assertThat(settings.getProperty(TestConfiguration.VERSION_NUMBER), equalTo(20));
|
||||
assertThat(settings.getProperty(TestConfiguration.SKIP_BORING_FEATURES), equalTo(true));
|
||||
assertThat(settings.getProperty(TestConfiguration.RATIO_LIMIT), equalTo(4.25));
|
||||
assertThat(settings.getProperty(TestConfiguration.SYSTEM_NAME), equalTo("myTestSys"));
|
||||
|
||||
assertDefaultValue(TestConfiguration.DURATION_IN_SECONDS, settings);
|
||||
assertDefaultValue(TestConfiguration.DUST_LEVEL, settings);
|
||||
@@ -68,7 +68,7 @@ public class NewSettingTest {
|
||||
|
||||
private static void assertDefaultValue(Property<?> property, NewSetting setting) {
|
||||
assertThat(property.getPath() + " has default value",
|
||||
setting.getOption(property).equals(property.getDefaultValue()), equalTo(true));
|
||||
setting.getProperty(property).equals(property.getDefaultValue()), equalTo(true));
|
||||
}
|
||||
|
||||
private static <T> Answer<T> withDefaultArgument() {
|
||||
|
||||
Reference in New Issue
Block a user